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

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

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


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?

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);


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

Hope that helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.