User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 427,219 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,206 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 1937 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 34
Reputation: adrive is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
adrive adrive is offline Offline
Light Poster

Putting an array into Tstringlist ?

  #1  
Dec 26th, 2007
Hi,

I can't seem to find any information at all...about how I can assign an Array into TStringList.

I'd like to do something like that :

for i:=0 to 10 do
begin

vArr[0] := intToStr(i);
vArr[1] := intToStr(i + 1);

vAStringList.addObject(inttostr(i), vArr);

end;

I'm trying to build a data structure that has similar name, but two different values sometimes :

Event A - ID 1
Event A - ID 2
Event B - ID 55
Event C - ID 12


Is this possible?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Zagreb, Croatia
Posts: 4
Reputation: Smola is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Smola's Avatar
Smola Smola is offline Offline
Newbie Poster

Re: Putting an array into Tstringlist ?

  #2  
Dec 26th, 2007
Well, I didn't try it but it seems possible.

First, if you use static arrays you'l have to define their size. You must use pointers to these arrays, and afterward you must free the allocated memory. It's a mess. )

You can also use records but that also involves pointers and freeing memory.

This shoud be done:

- define an array as a type
- define a pointer to the array-type
- allocate new memory with apropriate size and assign to the pointer
- fill the array with values through the pointer
- add the pointer to the string-list by casting it to the TObject

And repeat this for each element.

I would sugest another thing. Use TList to store your values and add a list to the stringlist element.

ListA, ListB : TList; // actually, you can use only one variable :)

ListA := TList.Create;
ListA.Add( pointer(1) );
ListA.Add( pointer(2) );
StringList.AddObject('Event A', ListA);

ListB := TList.Create;
ListB.Add( pointer(55) );
StringList.AddObject('Event B', ListB);

etc..


List := TList( StringList.Objects[0] ); // getting values for the element
i := integer(  List[0] ); // casting to integer to get the value at position 0

for i := 0 to StrinList.Count - 1 do StringList.Objects[i].Free; // freeing the lists
StringList.Free;

Hope that helped.
Doom on, soldier.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 11:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC