Sign in Join
Wiki copytemporary

TStringList: what changed

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

OldNewLine
11A **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.
22
33Inheritance
44
55- [[TObject]] - Base [[Class|class]] of all classes.
66 - [[TPersistent]], [[IFPObserved]] - Base class for streaming system and persistent properties - Interface implemented by an object that can be observed.
77 - [[TStrings]] - Class to manage arrays or collections of strings
88 - **TStringList** - Standard implementation of the TStrings class.
99
1010TStringList 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.
1111
1212Example
1313
1414``` pascal
1515 // get a value from file FILNAM filled with key=value pairs
1616function GetValueFromFile( filnam: string, key: string ): string;
1717var
1818 lst: TStringList;
1919 v: String;
2020begin
2121 lst := TStringList.Create();
2222 lst.CaseSensitive := false;
2323 lst.Duplicates := dupIgnore; // do not add duplicates
2424 lst.Sorted := true;
2525 lst.LoadFromFile( filnam );
2626 v := lst.Values[ key ];
2727 lst.Free();
2828 result := v;
2929end;
3030```
3131
3232TStringlist also has a 'builtin' data dictionary mode, here is an example provided by forum user Remy Lebeau
3333
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;`
34+``` pascal
35+ uses
36+ ..., Classes;
37+
38+ var
39+ SL: TStringList;
40+ Value: Integer;
41+ begin
42+ SL := TStringList.Create;
43+ try
44+ SL.Add('VarName=99');
45+ ...
46+ Value := StrToInt(SL.Values['VarName']);
47+ ...
48+ finally
49+ SL.Free;
50+ end;
51+ end;
52+```
5153
5254## See also
5355
5456- [[doc:rtl/classes/tstringlist.html|TStringList doc]]
5557- [[TStringList-TStrings Tutorial]]
5658- [[TBufStream|example of saving a TStringList to disk faster than the SaveToFile method can]]
5759
5860---
5961*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