Results 1 to 6 of 6

Thread: Array mysteriously out of range...

  1. #1
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Array mysteriously out of range...

    I have a function that takes a TPointArray and performs an action on it, resulting in a second, changed TPointArray. Here's my code:

    SCAR Code:
    function FixPoints(ArrayVar : TPointArray) : TPointArray;
    var
      i : integer;
    begin
      i := getarraylength(ArrayVar);
      setarraylength(Result, i);
      i := 0;
      repeat
      Result[i].x := ArrayVar[i].x; //HERE'S MY ERROR :(
      Result[i].y := (ArrayVar[i].y * -1) + height - 7;
      i := i + 1;
      writeln('doing for '+inttostr(i));
      until(i = getarraylength(ArrayVar));
    end;

    And I get the following error:

    [Runtime Error] : Out Of Range in line 29 in script (path to script).

    I really don't know why it should be out of range. I used getarraylength and setarraylength to make the lengths the same. WTF is going on???

    Someone please help me. Thanks a lot in advance .

    It's been a while... but I'm BACK!!!

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Just do result:=arrayvar in the beginning

  3. #3
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Same problem. It won't go away . And I know for 100% that the array contains something. Every ArrayVar.x and .y is filled to the brink with numbers.

    It's been a while... but I'm BACK!!!

  4. #4
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by botmaster View Post
    I have a function that takes a TPointArray and performs an action on it, resulting in a second, changed TPointArray. Here's my code:

    SCAR Code:
    function FixPoints(ArrayVar : TPointArray) : TPointArray;
    var
      i : integer;
    begin
      i := getarraylength(ArrayVar);
      setarraylength(Result, i);
      i := 0;
      repeat
      Result[i].x := ArrayVar[i].x; //HERE'S MY ERROR :(
      Result[i].y := (ArrayVar[i].y * -1) + height - 7;
      i := i + 1;
      writeln('doing for '+inttostr(i));
      until(i = getarraylength(ArrayVar));
    end;

    And I get the following error:

    [Runtime Error] : Out Of Range in line 29 in script (path to script).

    I really don't know why it should be out of range. I used getarraylength and setarraylength to make the lengths the same. WTF is going on???

    Someone please help me. Thanks a lot in advance .
    This wont work ofcourse, you set the array to zero, then start filling it?
    PM me (so I wont forget), I will correct it later, I am too tired now.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  5. #5
    Join Date
    Feb 2006
    Posts
    433
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Wizzup, he doesn't set to zero then start filling it, infact there is no error. All I can suggest is that the array you are using it for hasn't had it's length defined.

    Try this..

    SCAR Code:
    program Script;

    var
      Test : array of TPoint;

    function FixPoints(ArrayVar : TPointArray) : TPointArray;
    var
      i : integer;
    begin
      i := getarraylength(ArrayVar);
      setarraylength(Result, i);
      i := 0;
      repeat
      Result[i].x := ArrayVar[i].x; //HERE'S MY ERROR :(
      Result[i].y := (ArrayVar[i].y * -1) { + height } - 7;
      i := i + 1;
      writeln('doing for '+inttostr(i));
      until(i = getarraylength(ArrayVar));
    end;

    begin
     SetArrayLength(Test, 2);
     FixPoints(Test);
    end.

  6. #6
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    SCAR Code:
    function FixPoints(ArrayVar: TPointArray): TPointArray;
    var
      i: Integer;
    begin
      Result := ArrayVar;
      for i := 0 to GetArrayLength(Result) - 1 do
        Result[i].y := (Result[i].y * -1) + height - 7;
    end;
    Shorter

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Array in an array...
    By Lorax in forum OSR Advanced Scripting Tutorials
    Replies: 20
    Last Post: 01-16-2010, 09:10 PM
  2. ItemColors: Array of Array of Integer
    By n3ss3s in forum Research & Development Lounge
    Replies: 5
    Last Post: 10-30-2007, 06:04 PM
  3. Array of Tbox - And TPoint array helps.
    By R0b0t1 in forum OSR Help
    Replies: 4
    Last Post: 06-10-2007, 06:43 PM
  4. array help please
    By omgh4x0rz in forum OSR Help
    Replies: 4
    Last Post: 02-18-2007, 05:30 PM

Posting Permissions

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