Null terminated StringList

Quote
David Bannon (D.Ban...@latrobe.edu.au) wrote:

|      I need an object that has the function of the really
| nice TStringList but is not limited to strings of 256 char
| long. Does any one know of any work in this direction or do I
| have to start from scratch ?

Try creating an object that encapsulates a TList and declares PChars.
Here is an example. I haven't added anything nice like LoadFromFile
and SaveToFile and IndexOf, but I'm sure you can figure this out.
I don't garuntee that this works as is, because I just converted
it online from my TIntList class, which is extremely less complicated.
(Oh, change the name to TPCharList, I suppose):

  TIntList = class(TObject)
  private
    FList: TList;
    function GetItems(Item: integer): PChar;
    procedure SetItems(Item: integer; Value: PChar);
    function GetCount: integer;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Clear;
    procedure Delete(Index: integer);
    function Add(Value: PChar): integer;
    property Items[Item: integer]: PChar read GetItems write SetItems; default;
    property Count: integer read GetCount;
  end;

function TIntList.GetItems(Item: integer): PChar;
begin
  Result:=PChar(FList[Item]);
end;

procedure TIntList.SetItems(Item: integer; Value: PChar);
var
  StrPtr: PChar;
begin
  FreeMem(Items[Item], StrLen(Items[Item]) + 1);
  GetMem(StrPtr, StrLen(Value) + 1);
  StrCopy(StrPtr, Value);
  FList[Item]:=StrPtr;
end;

function TIntList.GetCount: integer;
begin
  Result:=FList.Count;
end;

constructor TIntList.Create;
begin
  inherited Create;
  FList:=TList.Create;
end;

destructor TIntList.Destroy;
begin
  Clear;
  FList.Free;
  inherited Destroy;
end;

procedure TIntList.Clear;
var
  Index: integer;
begin
  for Index:=0 to FList.Count - 1 do
    FreeMem(FList.Items[Index], StrLen(Items[Index]) + 1);
  FList.Clear;
end;

procedure TIntList.Delete(Index: integer);
begin
  FreeMem(FList.Items[Index], StrLen(Items[Index]) + 1);
  FList.Delete(Index);
end;

function TIntList.Add(Value: PChar): integer;
var
  StrPtr: PChar;
begin
  GetMem(StrPtr, StrLen(Value) + 1);
  StrCopy(StrPtr, Value);
  Result:=FList.Add(StrPtr);
end;

--
Joseph S. Bui's Standard Disclaimer:
I love you.