JonathanBriggs Posted January 23, 2009 Posted January 23, 2009 HelloCan 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!
WildBill Posted January 29, 2009 Posted January 29, 2009 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.
JonathanBriggs Posted February 5, 2009 Author Posted February 5, 2009 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
WildBill Posted February 22, 2009 Posted February 22, 2009 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.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now