Board index » delphi » Newbie Q: how to store a string in TList

Newbie Q: how to store a string in TList

Hi there!

I have a question: how do you store a simple string in a TList object?

IMHO is this the only way to create a dynamic array in Delphi 2, and
because in this case I really can't tell what the size of the array
will be, i -must- use a dynamic one.

Please help me!! I'm stuck.
BTW: Please reply via E-Mail...

Alex Braber
abra...@pi.net
The Netherlands

 

Re:Newbie Q: how to store a string in TList


For you case, use a TStringList, like this...

var
   MyList: TStringList;
begin
   MyList := TStringList.Create;
   MyList.Add('String1');
   MyList.Add('String2');
   MyList.Add('String3');
   MyList.Add('String4');
   MyList.Add('String5');
   MyList.Add('String6');
   ...
end;

As for referencing the count of items in the list, do this
   ItemCount := MyList.Count;

The fun is only just beginning...

Mr. Wrong <mr_wr...@pi.net> wrote in article
<3227858c.5649...@news.pi.net>...

Quote
> Hi there!

> I have a question: how do you store a simple string in a TList object?

> IMHO is this the only way to create a dynamic array in Delphi 2, and
> because in this case I really can't tell what the size of the array
> will be, i -must- use a dynamic one.

> Please help me!! I'm stuck.
> BTW: Please reply via E-Mail...

> Alex Braber
> abra...@pi.net
> The Netherlands

Re:Newbie Q: how to store a string in TList


Quote
Mr. Wrong wrote:

> Hi there!

> I have a question: how do you store a simple string in a TList object?

> IMHO is this the only way to create a dynamic array in Delphi 2, and
> because in this case I really can't tell what the size of the array
> will be, i -must- use a dynamic one.

> Please help me!! I'm stuck.
> BTW: Please reply via E-Mail...

> Alex Braber
> abra...@pi.net
> The Netherlands

You May want to use a TStringList instead of TList to hold you string.
It is built off of TList and designed specificly to handle strings.

Mike

Other Threads