function NewStrList: PStrList;
Creates string list object.
function WStrLen( W: PWideChar ): Integer;
Returns Length of null-terminated Unicode string.
function NewStrListEx: PStrListEx;
Creates extended string list object.
procedure WStrCopy( Dest, Src: PWideChar );
Copies null-terminated Unicode string (terminated null also copied).
procedure ( Dest, Src: PWideChar; MaxLen: Integer );
Copies null-terminWStrLCopyated Unicode string (terminated null also copied).
function WStrCmp( W1, W2: PWideChar ): Integer;
Compares two null-terminated Unicode strings.
function WStrCmp_NoCase( W1, W2: PWideChar ): Integer;
Compares two null-terminated Unicode strings.
function NewWStrList: PWStrList;
Creates new TWStrList object and returns a pointer to it.
function NewWStrListEx: PWStrListEx;
Creates new TWStrListEx objects and returns a pointer to it.
function NewKOLStrList: PKOLStrList;
function NewKOLStrListEx: PKOLStrListEx;
TStrList
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).
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 indexes.
procedure Sort( CaseSensitive: Boolean );
Call it to sort string list.
procedure AnsiSort( CaseSensitive: Boolean );
Call it to sort ANSI string list.
procedure SortEx( const CompareFun: TCompareEvent );
Call it to sort via your own compare procedure
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.
TStrListEx
TStrListEx( unit KOL.pas ) TStrList TObj _TObj
TStrListEx = object( TStrList )
Extended string list object. Has additional capability to associate numbers or objects with string list items.
TStrListEx properties
property Objects[ Idx: Integer ]: DWORD;
Objects are just 32-bit values. You can treat and use it as pointers to any other data in the memory. But it is your task to free allocated memory in such case therefore.
If the last item of a string list is deleted vis DeleteLast method (but not via Delete method), it's object still is preserved. As well, it is possible to set Objects[idx] for idx >= Count. To get know object's count, rather then strings count, use ObjectCount property.
property ObjectCount: Integer;
Returns number of objects available. This value can differ from Count after some operations: objects are stored in the independant list and only synchronization is provided while using methods Delete, Insert, Add, AddObject, InsertObject while changing the list.
Properties, inherited from TStrList
TStrListEx methods
procedure AddStrings( Strings: PStrListEx );
Merges string list with given one. Very fast - more preferrable to use than any loop with calling Add method.
procedure Assign( Strings: PStrListEx );
Fills string list with strings from other one. The same as AddStrings, but Clear is called first.
Makes string list empty.
procedure Delete( Idx: integer );
Deletes string with given index (it *must* exist).
Deletes the last string and correspondent object in the list.
procedure Move( CurIndex, NewIndex: integer );
Moves string to another location.
procedure Swap( Idx1, Idx2: Integer );
Swaps to strings with given indexes.
procedure Sort( CaseSensitive: Boolean );
Call it to sort string list.
procedure AnsiSort( CaseSensitive: Boolean );
Call it to sort ANSI string list.
function LastObj: DWORD;
Object assotiated with the last string.
function AddObject( const S: AnsiString; Obj: DWORD ): Integer;
Adds a string and associates given number with it. Index of the item added is returned.
procedure InsertObject( Before: Integer; const S: AnsiString; Obj: DWORD );
Inserts a string together with object associated.
function IndexOfObj( Obj: Pointer ): Integer;
Returns an index of a string associated with the object passed as a parameter. If there are no such strings, -1 is returned.
TWStrList
TWStrList( unit KOL.pas ) TObj _TObj
TWStrList = object( TObj )
String list to store Unicode (null-terminated) strings.
TWStrList properties
property Items[ Idx: Integer ]: KOLWideString;
See also TStrList.Items
property ItemPtrs[ Idx: Integer ]: PWideChar;
See also TStrList.ItemPtrs
See also TStrList.Count
See also TStrList.Text
Properties, inherited from TObj
TWStrList methods
procedure SetText( const Value: KOLWideString );
See also TStrList.SetText
See also TStrList.Clear
function Add( const W: KOLWideString ): Integer;
See also TStrList.Add
procedure Insert( Idx: Integer; const W: KOLWideString );
See also TStrList.Insert
procedure Delete( Idx: Integer );
See also TStrList.Delete
procedure AddWStrings( WL: PWStrList );
See also TStrList.AddStrings
procedure Assign( WL: PWStrList );
See also TStrList.Assign
function LoadFromFile( const Filename: KOLString ): Boolean;
See also TStrList.LoadFromFile
procedure LoadFromStream( Strm: PStream; AppendToList: Boolean );
See also TStrList.LoadFromStream
function MergeFromFile( const Filename: KOLString ): Boolean;
See also TStrList.MergeFromFile
procedure MergeFromStream( Strm: PStream );
See also TStrList.MergeFromStream
function SaveToFile( const Filename: KOLString ): Boolean;
See also TStrList.SaveToFile
procedure SaveToStream( Strm: PStream );
See also TStrList.SaveToStream
function AppendToFile( const Filename: KOLString ): Boolean;
See also TStrList.AppendToFile
procedure Swap( Idx1, Idx2: Integer );
See also TStrList.Swap
procedure Sort( CaseSensitive: Boolean );
See also TStrList.Sort
procedure Move( IdxOld, IdxNew: Integer );
See also TStrList.Move
function IndexOf( const s: KOLWideString ): Integer;
function IndexOf_NoCase( const s: KOLWideString ): Integer;
procedure Put( Idx: integer; const Value: KOLWideString );