Is it always like
SetLength(mTile[X, Y].Animation.Frames, High(mTile[X, Y].Animation.Frames)+2);
or does it depend on the sizeof(frames) ?
Is it always like
SetLength(mTile[X, Y].Animation.Frames, High(mTile[X, Y].Animation.Frames)+2);
or does it depend on the sizeof(frames) ?
I have a 2005 CRF 250 so <^>(><<^>
<br />http://www.gtrpg.com/
Don't use SizeOf in this context, use Length. SizeOf will return the Byte-Size of the pointer which is always 4 bytes. Length will return the number of elements in a dynamic array. To append an element to a dynamic array, do this:
SetLength(Frames, Length(Frames) + 1);
Frame[Length(Frames) - 1].Color := clGreen;
Ask me about the xcess game development kit
Doesn't High() do it?
I have a 2005 CRF 250 so <^>(><<^>
<br />http://www.gtrpg.com/
yeah, high() will do it, too
Ask me about the xcess game development kit
Whats the difference between the output of High() and Length() ?
And this is acting very strange: (giving me range check error after like 3 iterations of this functions)
[pascal]SetLength(mTile[X, Y].Animation.Frames, Length(mTile[X, Y].Animation.Frames)+1);
mTile[X, Y].Animation.Frames[Length(mTile[X, Y].Animation.Frames)-1].TileIndex := frmMain.cTileID - (Trunc(frmMain.cTileID div 112) * 112);
mTile[X, Y].Animation.Frames[Length(mTile[X, Y].Animation.Frames)-1].TextureIndex := Trunc(frmMain.cTileID div 112);[/pascal]
I have a 2005 CRF 250 so <^>(><<^>
<br />http://www.gtrpg.com/
Length() returns the number of elements in an array (or the length of a string); High() returns the index of the last element in an array - usually this is Length()-1. There is also the Low() function, which returns the index of the first element in an array, and will in nearly every case be 0. It is, however, possible in Delphi to have static arrays that do not start at index 0, for example if you are using an enum as the index.Originally Posted by xGTx
[size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]
I think Dynamic arrays always start at 0.
William Cairns
My Games: http://www.cairnsgames.co.za (Currently very inactive)
MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)
Thats exactly right, they always start at 0. When youOriginally Posted by cairnswm
[pascal]var dArray : Array of Char;
SetLength(dArray, 20);[/pascal]
dArray will be from 0 to 19. Then
[pascal]a := Length(dArray);
// a = 20
b := High(dArray);
// b = 19
c := Low(dArray);
// c = 0[/pascal]
Just be careful how you use Dynamic arrays within other data structures. The effects can be a bit unpredictable. Misuse of them is what would result in a 'memory leak' in your program. Dynamic Arrays within dynamic arrays is also highly UNrecommended(if your program will even function properly). You re pretty much dealing with memory management when you play with them.
Thanks alot guys. Now removing from a dynamic array is
[pascal]
SetLength(Frames, High(Frames)-1);
[/pascal]
Since high() is the actuall number of elements in the array and -1 would drop it down 1. Correct?
I have a 2005 CRF 250 so <^>(><<^>
<br />http://www.gtrpg.com/
No, High is the last index of the array and Length is the count.
To delete the last item do this
[pascal]SetLength(MyArray, Length(MyArray) - 1);[/pascal]
or this
[pascal]SetLength(MyArray, High(MyArray));[/pascal]
Ask me about the xcess game development kit
Bookmarks