TPDFlibStringList

Data types

Description

TPDFlibStringList is a self-contained list of AnsiString entries, each with an optional TObject, modelled on the classic TStringList surface but implemented inside PDFlibExtra without descending from the VCL class, so it is usable in builds that do not link the VCL.

Comparisons are case-insensitive by default through PLAnsiCompareText, and TPDFlibCaseSensitiveStringList derives from it to compare case-sensitively. Setting Sorted sorts the current entries and turns later additions into binary-search insertions.

Syntax

Delphi

TPDFlibStringList = Class
  Public
    Constructor Create; Virtual;
    Destructor Destroy; Override;
    Function Add(Const S: AnsiString): Integer;
    Function IndexOf(Const S: AnsiString): Integer;
    Function IndexOfObject(AObject: TObject): Integer;
    Function IndexOfName(Const Name: AnsiString): Integer;
    Procedure InsertObject(Index: Integer; Const S: AnsiString; AObject: TObject);
    Function AddObject(Const S: AnsiString; AObject: TObject): Integer;
    Procedure Clear;
    Procedure AddStrings(Strings: TPDFlibStringList);
    Procedure Delete(Index: Integer);
    Procedure Insert(Index: Integer; Const S: AnsiString);
    Procedure SaveToFile(Const FileName: WideString);
    Procedure SaveToStream(Stream: TStream);
    Procedure Sort;
    Function Find(Const S: AnsiString; Var Index: Integer): Boolean;
    Property Duplicates: TDuplicates
      Read FDuplicates
      Write FDuplicates;
    Property Count: Integer
      Read GetCount;
    Property Capacity: Integer
      Read GetCapacity
      Write SetCapacity;
    Property Text: AnsiString
      Read GetTextStr
      Write SetTextStr;
    Property Sorted: Boolean
      Read FSorted
      Write SetSorted;
    Property Objects[Index: Integer]: TObject
      Read GetObject
      Write PutObject;
    Property Strings[Index: Integer]: AnsiString
      Read Get
      Write Put;
      Default;
    Property Values[Const Name: AnsiString]: AnsiString
      Read GetValue
      Write SetValue;
  End;

Fields

Strings[Index] / Objects[Index]Default indexed access to the text and its associated object; an out-of-range read yields an empty string or Nil and an out-of-range write is ignored; the list does not own the objects
Count / CapacityCurrent entry count and allocated slots; the capacity never drops below the count and grows automatically
Add / AddObjectAppend an entry and return its index; in sorted mode duplicates follow the Duplicates policy
Insert / InsertObject / AddStringsInsert at a position, or append the entries and objects of another list; invalid insert positions are ignored
IndexOf / IndexOfObject / IndexOfNameLocate by text, by object reference or by the name part before the first =; case-insensitive unless a case-sensitive instance is used
FindBinary search that returns whether the text exists and the matching or insertion index; it assumes a sorted list
Values[Name]Name/value convenience: reads the text after the first = and writes or deletes the matching entry
Sorted / DuplicatesSort state and duplicate policy (dupIgnore, dupAccept, dupError); the policy applies to sorted additions
Sort / Clear / DeleteReorder all entries, drop every entry, or remove one by index
SaveToFile / SaveToStreamWrite each entry followed by CRLF as AnsiString content; SaveToFile creates or truncates the file

Remarks

Duplicate handling is consulted only while the list is sorted: an unsorted Add appends even when Duplicates is dupIgnore, and dupError raises EListError only in sorted mode.

Text reads and writes CR/LF-delimited content; the setter clears the list first, skips empty tokens, and an empty string produces one empty entry.

Values does not trim or unquote; it returns whatever follows the first = and deletes the entry when assigned an empty value.

The list never frees the objects stored alongside strings, so the caller keeps ownership; Clear, Delete and the destructor release only the strings.

See also

MiscellaneousFunctions