PDA

View Full Version : transferring data to list item.



marmin
15-07-2006, 08:37 PM
Hello,

The following problem has arisen:

I have created a complex record

Foo2 = record
__foo2byte: array of byte;
end;

Foo1 = record
__Foo1: array of Foo2;
end;

PTest = ^TTest;
TTest = record
_1: array of Foo1;
end;


var
Ttest_1 : TTest;

filling Ttest_1 with data, I set all arrays in the program using setlength and fill in the data. I also have created a linked list, of the pointer type Ptest. Now, I want to fill a new item of the list with Ttest_1.

Question:

- How can the new instance of the list 'know' all the dimensions of the array's I set in Ttest_1?
- Is there a fast way to fill in all the data of Ttest_1 in the new list item?

tanffn
16-07-2006, 04:00 AM
I'm not really sure if thats what you need.. but here it goes anyway :)


For I:= Low(Ttest_1._1) to High(Ttest_1._1) do
Ttest_1._1[I].....


Why don't you use TObjectList, A little bit more work on class design/write but your main code will look a lot nicer!

marmin
16-07-2006, 01:39 PM
Thanks for the reply!
Well, as for object Pascal I think the only bug-free solution is to set all dynamic arrays of the new list item just like I do with Ttest_1. And use a for..next loop to transfer the data. It's pain because I have to do it every time I create a new item!.
I could also use an Object and a TList.. but I'd like to avoid o.o.p. A.M.A.P. :lol: I want to understand the fundament.

tanffn
17-07-2006, 06:32 AM
You can create other types of data structures that are more efficient then O(n) :wink: , as I don’t know what you need it for I can’t direct you to a specific method.

marmin
23-07-2006, 03:50 PM
Surprise me.. :P I have a (fixed) array of weapon types, and an in-game linked list of weapons. Each time a weapon is fired, an item is added to the list, and the specific weapon type data from the array, is put into this new list item (which is of course of the same type). No OOP! :lol: