Sign in Join
Wiki copytemporary

TStringList

English · Polski · Suomi

A TStringList is a datatype that can hold an arbitrary length list of 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.

Inheritance

TStringList adds sorting functionality to TStrings by adding properties Sorted, Duplicates and CaseSensitive and methods like Find to facilitate speeded search within a list.

Example

pascal
  // get a value from file FILNAM filled with key=value pairs 
function GetValueFromFile( filnam: string, key: string ): string;
var
  lst: TStringList;
  v: String;
begin
  lst := TStringList.Create();
  lst.CaseSensitive := false;
  lst.Duplicates := dupIgnore; // do not add duplicates
  lst.Sorted := true;
  lst.LoadFromFile( filnam );
  v := lst.Values[ key ];
  lst.Free();
  result := v;
end;

TStringlist also has a 'builtin' data dictionary mode, here is an example provided by forum user Remy Lebeau

pascal
   uses
     ..., Classes;
    
   var
     SL: TStringList;
     Value: Integer;
   begin
     SL := TStringList.Create;
     try
       SL.Add('VarName=99');
       ...
       Value := StrToInt(SL.Values['VarName']);
       ...
     finally
       SL.Free;
     end;
   end;

See also


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.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.