TStrList( unit KOL.pas ) ï TObj ï _TObj

TStrList = object( TObj )

Easy string list implementation (non-visual, just to store string data). It is well improved and has very high performance allowing to work fast with huge text files (more then megabyte of text data). Please note that #0 charaster if stored in string lines, will cut it preventing reading the rest of a line. Be careful, if your data contain such characters.

TStrList properties

property Values[ const AName: Ansistring ]: Ansistring;
by Dod. Returns right side of a line starting like Name=...

property Count: integer;    Ñ   
Number of strings in a string list.

property Items[ Idx: integer ]: Ansistring; default;
Strings array items. If item does not exist, empty string is returned. But for assign to property, string with given index *must* exist.

property ItemPtrs[ Idx: Integer ]: PAnsiChar;    Ñ   
Fast access to item strings as PChars.

property Text: Ansistring;
Content of string list as a single string (where strings are separated by characters $0D,$0A).

Properties, inherited from TObj

TStrList methods

function IndexOfName( AName: Ansistring ): Integer;
by Dod. Returns index of line starting like Name=...

function Add( const S: Ansistring ): integer;
Adds a string to list.

procedure AddStrings( Strings: PStrList );
Merges string list with given one. Very fast - more preferrable to use than any loop with calling Add method.

procedure Assign( Strings: PStrList );
Fills string list with strings from other one. The same as AddStrings, but Clear is called first.

procedure Clear;
Makes string list empty.

procedure Delete( Idx: integer );
Deletes string with given index (it *must* exist).

procedure DeleteLast;
Deletes the last string (it *must* exist).

function IndexOf( const S: AnsiString ): integer;
Returns index of first string, equal to given one.

function IndexOf_NoCase( const S: Ansistring ): integer;
Returns index of first string, equal to given one (while comparing it without case sensitivity).

function IndexOfStrL_NoCase( Str: PAnsiChar; L: Integer ): integer;
Returns index of first string, equal to given one (while comparing it without case sensitivity).

function Find( const S: AnsiString; var Index: Integer ): Boolean;
Returns Index of the string, equal or greater to given pattern, but works only for sorted TStrList object. Returns TRUE if exact string found, otherwise nearest (greater then a pattern) string index is returned, and the result is FALSE. And in such _case Index is returned negated when the S string is less then the string found.

function FindFirst( const S: AnsiString; var Index: Integer ): Boolean;
Like above but always returns Index of the first string, equal or greater to given pattern. Also works only for sorted TStrList object. Returns TRUE if exact string found, otherwise nearest (greater then a pattern) string index is returned, and the result is FALSE.

procedure Insert( Idx: integer; const S: Ansistring );
Inserts string before one with given index.

procedure Move( CurIndex, NewIndex: integer );
Moves string to another location.

procedure SetText( const S: Ansistring; Append2List: Boolean );
Allows to set strings of string list from given string (in which strings are separated by $0D,$0A or $0D characters). Text must not contain #0 characters. Works very fast. This method is used in all others, working with text arrays (LoadFromFile, MergeFromFile, Assign, AddStrings).

procedure SetUnixText( const S: AnsiString; Append2List: Boolean );
Allows to assign UNIX-style text (with #10 as string separator).

function Last: AnsiString;
Last item (or '', if string list is empty).

procedure Swap( Idx1, Idx2: Integer );
Swaps to strings with given indeces.

procedure Sort( CaseSensitive: Boolean );
Call it to sort string list.

procedure AnsiSort( CaseSensitive: Boolean );
Call it to sort ANSI string list.

function Join( const sep: AnsiString ): AnsiString;
by Sergey Shishmintzev.

function LoadFromFile( const FileName: KOLString ): Boolean;
Loads string list from a file. (If file does not exist, nothing happens). Very fast even for huge text files.

procedure LoadFromStream( Stream: PStream; Append2List: Boolean );
Loads string list from a stream (from current position to the end of a stream). Very fast even for huge text.

procedure MergeFromFile( const FileName: KOLString );
Merges string list with strings in a file. Fast.

function SaveToFile( const FileName: KOLString ): Boolean;
Stores string list to a file.

procedure SaveToStream( Stream: PStream );
Saves string list to a stream (from current position).

function AppendToFile( const FileName: KOLString ): Boolean;
Appends strings of string list to the end of a file.

Methods, inherited from TObj

TStrList events

Events, inherited from TObj

TStrList fields

Fields, inherited from TObj


Index ]

This help is generated 14-Jun-2010 by KOL Help generator, (C) 2000-2001 by Vladimir Kladov
Modified (C) 2003 by Alexander Bartov