•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Posts: 34
Reputation:
Rep Power: 1
Solved Threads: 0
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?
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?
•
•
Join Date: Dec 2007
Location: Zagreb, Croatia
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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.
Hope that helped.

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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: Poisson distribution
- Next Thread: Clientdatasets and MySQL


Linear Mode