Ross

> I see, it is C.
> I have managed to get it to work! if I make it a static array rather than
dynamic (as
> in the C example).
> eg. categories : array[0..500] of TStringList
> I would rather have it dynamic because the number of elements is unknown.
Is there
> no easy way around it?

I was about to send this when I saw your post.    Yes the problem
in your earlier example was that the array wasn't allocated.

here's an example of 2 ways to do it - Categories is a "statically allocated
array" and MyStrings is "dynamically allocated"

var
  Categories : array[0..9] of TStringList;
  MyStrings: Tlist;
  i:integer;
begin
  MyStrings:= TList.Create;

  for i := 0 to 9
  do begin
    Categories[i] := TStringList.Create;
    MyStrings.Add(TStringlist.Create);
  end;
end;

You can access the MyStrings collection like an array
(i.e. MyStrings[k] is the kth TStringList)   but as I
have it written you will need to typecast the result
because the generic TList is a container for TObjects.
So actually you would need TStringList(MyStrings[k]).

For industrial use, I'd suggest deriving your own
class from TList  -    so that the Add() function
takes only TStringlists) and the [] operation returns
a TStringlist instead of a TObject.

Hope this is useful

-ns



---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to