Jump to content

Recommended Posts

Posted

Hello

Can anyone tell me how to dynamically create a string list, based on a prefix and a loop counter.

Hopefully, this pusedo code below will help explain what i am looking for...

Delphi 7.

for i:=0to Count-1do

begin

StringListPrefix+:=TStringList.Create;

Thanks for any help!


Posted

Do you mean something like this?

Type
TStringListArray = Array Of TStringList;

Var
StringListArray = TStringListArray;

Procedure DestroyStringLists(Var ListArray: TStringListArray);
Var I: Integer;
Begin
For I := 0 To High(ListArray) Do ListArray[I].Free;
SetLength(ListArray,0);
End;

Procedure AllocateStringLists(Var ListArray: TStringListArray; Count: Integer);
Begin
// If anything is already in the list, get rid of it

DestroyStringLists(ListArray);

// Allocate String Lists

SetLength(ListArray,Count);
For I := 0 To Count - 1 Do ListArray[I] := TStringList.Create;
End;

Begin
// Test code

AllocateStringLists(StringListArray);

// Do something with the lists we created...

// Destroy everything

DestroyStringLists(StringListArray);
End;

You could also accomplish this by using a TStringList itself instead of an open array, but this is type-safe.

Posted

Hello WildBill,

Yes! that was exactly what i was after. However, i ended up rewriting the whole function without the need for this unknown amount of string lists... its quite a good wee idea, hope you dont mind if i add it to my collection :)

  • 3 weeks later...
Posted

You're welcome. If you ever need associative lists (hashes), you might want to take a look at the STHashes unit in SmoothText's source code. It's in the Win2000 section. Delphi never came with decent hash code and I needed to write it to fill the gap.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...