Board index » delphi » Another Stringlist {*word*218} question ?
L. Healy
![]() Delphi Developer |
Sun, 03 Apr 2005 22:33:29 GMT
|
L. Healy
![]() Delphi Developer |
Sun, 03 Apr 2005 22:33:29 GMT
Another Stringlist {*word*218} question ?
Hello for the second time today,
I have 6 stringlists : SL1 and an integer - 'i' What is the best way to do something like this which gets the 1st item For i := 1 to 6 do begin SL+(i)[0]; //get 1st item in list for all 6 stringlists end; and so on. Thanks. |
Sundial Service
![]() Delphi Developer |
Sun, 03 Apr 2005 22:59:06 GMT
Re:Another Stringlist {*word*218} question ?Well, you could put the six lists onto a TList. Here's one way to do it: myList.Add(SL1); then: (myList[0] as TStringList)[4] [Naturally I'd probably create a class which encapsulates that logic and Remember that "objects are pointers," so when I "add SL1 to the list," I now Another way I could do the same thing is to create the TStringLists purely for n := 0 to 5 do myList.Add(TStringlist.Create); Now I've created six instances of a TStringList and have put them onto the for n := 0 to 5 do (myList[n] as TStringList).Free; The two statements should be adjacent because when I free object "n" the Quote>L. Healy wrote: Fast automatic Paradox table repair at a click of a mouse! http://www.sundialservices.com/products/chimneysweep |
Jeremy Collin
![]() Delphi Developer |
Sun, 03 Apr 2005 23:18:41 GMT
Re:Another Stringlist {*word*218} question ?On Wed, 16 Oct 2002 15:33:29 +0100, "L. Healy" Quote<L.He...@occpsy.demon.co.uk> wrote: array too, which is probably simpler if you don't need a dynamcally changing number of TStringLists... var //... populate lists ... for i := 0 to 5 do -- |
Tom
![]() Delphi Developer |
Sun, 03 Apr 2005 23:24:30 GMT
Re:Another Stringlist {*word*218} question ?Quote"L. Healy" <L.He...@occpsy.demon.co.uk> wrote: these are 6 individual class instances NOT a multi-dimentional array. If there were only 6, maybe it'd be clearer just to say something ShowMessage(SL1[0]); But if there were more, or you don't like this solution you could // StringListArray is declared: array [1..6] of tStringList procedure SomeProc; HTH, Tom -- |
Koen V
![]() Delphi Developer |
Mon, 04 Apr 2005 00:13:20 GMT
Re:Another Stringlist {*word*218} question ?Hi, this won't work because you can't create names for variables at runtime. I think the best you can do is put the stringlists in an array, like this: var Then you can use the index to access the individual stringlists. ------------------------- "L. Healy" <L.He...@occpsy.demon.co.uk> schreef in bericht Quote> Hello for the second time today, |
AlanGLLo
![]() Delphi Developer |
Mon, 04 Apr 2005 04:08:37 GMT
Re:Another Stringlist {*word*218} question ?In article <AZXjALA5iXr9E...@occpsy.demon.co.uk>, "L. Healy" Quote<L.He...@occpsy.demon.co.uk> writes: stringgrid is a TStrings of the cell contents of row n. And the Cols[n] is a TStrings of the cell contents of column n. Personally I'd rather code a TList of TStringLists, or an array of Alan Lloyd |