Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Linked Lists

  1. #11

    Linked Lists

    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 <^>(>&lt<^>
    <br />http://www.gtrpg.com/

  2. #12

    Linked Lists

    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

  3. #13

    Linked Lists

    Doesn't High() do it?
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  4. #14

    Linked Lists

    yeah, high() will do it, too
    Ask me about the xcess game development kit

  5. #15

    Linked Lists

    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 &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  6. #16

    Linked Lists

    Quote Originally Posted by xGTx
    Whats the difference between the output of High() and Length() ?
    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.
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  7. #17
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Linked Lists

    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)

  8. #18
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Linked Lists

    Quote Originally Posted by cairnswm
    I think Dynamic arrays always start at 0.
    Thats exactly right, they always start at 0. When you
    [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.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  9. #19

    Linked Lists

    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 &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  10. #20

    Linked Lists

    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

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •