Excalibur81
asked on
dynamic array of records in dynamic array of records!!
Hey all,
I have a couple of records as follows :
type
WEAPON = record
size : byte;
posX : double;
posY : double;
posZ : double;
rotX : double;
rotY : double;
rotZ : double;
end;
type
DATA = record
LowestX : double;
LowestY : double;
HighestX : double;
HighestY : double;
weight : double;
braking : double;
power : double;
hitpoints : integer;
cost : integer;
name : string;
path : string;
WeaponsNumber : byte;
Weapons : array of WEAPON; //<---- right here!
end;
As u see, the DATA record has an array of WEAPON at the bottom.... ( as shown)
now i have a global dynamic array of DATA which works fine,
Tanks : array of DATA;
and i can call stuff like
SetLength(Tanks, 100);
Tanks[0].weight = 1000;
but when i call SetLength on the WEAPONS record within the DATA one, an access violation occurs...
i.e.
SetLength(Tanks[0].Weapons , 100); //Access violation!!!
Please help!!!
Regards,
-Rob-
I have a couple of records as follows :
type
WEAPON = record
size : byte;
posX : double;
posY : double;
posZ : double;
rotX : double;
rotY : double;
rotZ : double;
end;
type
DATA = record
LowestX : double;
LowestY : double;
HighestX : double;
HighestY : double;
weight : double;
braking : double;
power : double;
hitpoints : integer;
cost : integer;
name : string;
path : string;
WeaponsNumber : byte;
Weapons : array of WEAPON; //<---- right here!
end;
As u see, the DATA record has an array of WEAPON at the bottom.... ( as shown)
now i have a global dynamic array of DATA which works fine,
Tanks : array of DATA;
and i can call stuff like
SetLength(Tanks, 100);
Tanks[0].weight = 1000;
but when i call SetLength on the WEAPONS record within the DATA one, an access violation occurs...
i.e.
SetLength(Tanks[0].Weapons
Please help!!!
Regards,
-Rob-
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, even though it would slightly add complexity to your code, I would suggest you use a TList for this instead of a dynamic array.
Hi,
No access violation occurs in my Delphi 5. Everything is just fine:
var
Form1: TForm1;
Tanks : array of DATA;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender : TObject);
begin
SetLength(Tanks, 100);
Tanks[0].weight := 1000;
SetLength(Tanks[0].Weapons , 100);
Tanks[0].Weapons[0].PosX := 100.25;
ShowMessage(FloatToStr(Tan ks[0].Weap ons[0].Pos X));
end;
Regards, Geo
No access violation occurs in my Delphi 5. Everything is just fine:
var
Form1: TForm1;
Tanks : array of DATA;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender
begin
SetLength(Tanks, 100);
Tanks[0].weight := 1000;
SetLength(Tanks[0].Weapons
Tanks[0].Weapons[0].PosX := 100.25;
ShowMessage(FloatToStr(Tan
end;
Regards, Geo
btw, you could use length(tanks[n].weapons) instead of tanks[n].weaponnumber ;)
ASKER
Ahhh i see now, it was a logic mistake :)
Hmm, so since there was actually no problem, how do points work??
Also.....
"BTW, even though it would slightly add complexity to your code, I would suggest you use a TList for this instead of a dynamic array. "
Unfortunatly, im saving the data in a file which will be read later on by a program in C++, and needs to be in this fairly specific format.... thanks anyways :)
"btw, you could use length(tanks[n].weapons) instead of tanks[n].weaponnumber ;) "
Yes i had seen that, but for now im just using this for debugging purposes, but thanks also :)
Hmm, so since there was actually no problem, how do points work??
Also.....
"BTW, even though it would slightly add complexity to your code, I would suggest you use a TList for this instead of a dynamic array. "
Unfortunatly, im saving the data in a file which will be read later on by a program in C++, and needs to be in this fairly specific format.... thanks anyways :)
"btw, you could use length(tanks[n].weapons) instead of tanks[n].weaponnumber ;) "
Yes i had seen that, but for now im just using this for debugging purposes, but thanks also :)
I beleive you should split the points between geobul and myself. geobul, what do you suggest ?
jconde should get the points. I just confirmed that for D5.
ASKER
Thanks guys :)
Soz, i meant to split the points, but ive never done before, and i thought it was inside the "Accept Answer" path....
but i guess geobul didnt want them anyways :D
Thanks!!!
Soz, i meant to split the points, but ive never done before, and i thought it was inside the "Accept Answer" path....
but i guess geobul didnt want them anyways :D
Thanks!!!