Sign in Join
Wiki copytemporary

TStringList: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TStringList

OldNewLine
1+A **TStringList** is a [[Data type|datatype]] that can hold an arbitrary length list of [[String|strings]]. The strings in a TStringList are accessible as concatenated plain text or as a series of strings. Functionality is also provided for key-value pair access.
2+
3+Inheritance
4+
5+- [[TObject]] - Base [[Class|class]] of all classes.
6+ - [[TPersistent]], [[IFPObserved]] - Base class for streaming system and persistent properties - Interface implemented by an object that can be observed.
7+ - [[TStrings]] - Class to manage arrays or collections of strings
8+ - **TStringList** - Standard implementation of the TStrings class.
9+
10+TStringList adds sorting functionality to [[TStrings]] by adding properties `Sorted`, `Duplicates` and [[case-sensitive|CaseSensitive]] and [[Method|methods]] like `Find` to facilitate speeded search within a list.
11+
12+Example
13+
14+``` pascal
15+ // get a value from file FILNAM filled with key=value pairs
16+function GetValueFromFile( filnam: string, key: string ): string;
17+var
18+ lst: TStringList;
19+ v: String;
20+begin
21+ lst := TStringList.Create();
22+ lst.CaseSensitive := false;
23+ lst.Duplicates := dupIgnore; // do not add duplicates
24+ lst.Sorted := true;
25+ lst.LoadFromFile( filnam );
26+ v := lst.Values[ key ];
27+ lst.Free();
28+ result := v;
29+end;
30+```
31+
32+TStringlist also has a 'builtin' data dictionary mode, here is an example provided by forum user Remy Lebeau
33+
34+`   uses`\
35+`     ..., Classes;`\
36+`    `\
37+`   var`\
38+`     SL: TStringList;`\
39+`     Value: Integer;`\
40+`   begin`\
41+`     SL := TStringList.Create;`\
42+`     try`\
43+`       SL.Add('VarName=99');`\
44+`       ...`\
45+`       Value := StrToInt(SL.Values['VarName']);`\
46+`       ...`\
47+`     finally`\
48+`       SL.Free;`\
49+`     end;`\
50+`   end;`
51+
52+## See also
53+
54+- [[doc:rtl/classes/tstringlist.html|TStringList doc]]
55+- [[TStringList-TStrings Tutorial]]
56+- [[TBufStream|example of saving a TStringList to disk faster than the SaveToFile method can]]
57+
58+---
59+*From the Free Pascal wiki, page "TStringList", as it stood on 2021-08-29 after a change by Dbannon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history