Results 1 to 6 of 6

Thread: Out Of Range T2D...

  1. #1
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default Out Of Range T2D...

    Why does this give me out of range error at Line 24? I've already set the length -__- I even tried doing SetLength(....., (W*H) + 1);

    Basically I'm trying to dynamically make fonts.. It grabs all colours from a box (the box around the Max uptext).. Stores in a T2DPointArray along with the colours in a T2DIntegerArray..

    Does this once for each angle.. N, S, E, W.. Then match them.. if the colours are NOT the same, set them to 0.. aka black.. thus it should leave only the uptext in the array since those colours don't change.. Then makes a bitmap out of the data which can probably be cropped down to the right size per letter.

    I just can't get it to compile..

    Simba Code:
    {$I SRL/srl.Simba}
      {$I SRL/SRL/Misc/Debug.Simba}

    type
      TPAC = record
        TPA: T2DPointArray;
        TIA: T2DIntegerArray;
      end;

    Function GetTPACBox(B: TBox): TPAC;
    var
      Temp: TPAC;
      TP: TPoint;
      I, J, W, H: Integer;
    begin
      W:= B.X2 - B.X1;
      H:= B.Y2 - B.Y1;

      For I:= 0 To H do
        For J:= 0 To W do
        begin
          SetLength(Temp.TPA, Length(Temp.TPA) + 1);
          TP:= Point(B.X1 + J, B.Y1 + I);
          Temp.TPA[J][I]:= TP;

          SetLength(Temp.TIA, Length(Temp.TIA) + 1);
          Temp.TIA[J][I]:= GetColor(TP.X, TP.Y);
        end;
      Result:= Temp;
    end;

    Procedure GetTextBoxes;
    var
      Temp: Array of TPAC;
      B: TBox;
      I, J, K, BMP, W, H: Integer;
      TempI: TIntegerArray;
    begin
      B:= IntToBox(5, 5, 225, 20);
      SetLength(Temp, 4);
      Temp[0]:= GetTPACBox(B);
      MakeCompass('E');
      Temp[1]:= GetTPACBox(B);
      MakeCompass('S');
      Temp[2]:= GetTPACBox(B);
      MakeCompass('W');
      Temp[3]:= GetTPACBox(B);

      W:= B.X2 - B.X1;
      H:= B.Y2 - B.Y1;

      For I:= 0 To H do
        For I:= 0 To W do
          if ((Temp[0].TIA[J][I] <> Temp[1].TIA[J][I]) or (Temp[0].TIA[J][I] <> Temp[2].TIA[J][I]) or (Temp[0].TIA[J][I] <> Temp[3].TIA[J][I])) then
          begin
            Temp[0].TIA[J][I]:= 0;
            Temp[1].TIA[J][I]:= 0;
            Temp[2].TIA[J][I]:= 0;
            Temp[3].TIA[J][I]:= 0;
          end;

      BMP:= CreateBitmap(W, H);

      K:= 0;
      For I:= 0 To H do
        For J:= 0 To W do
        begin
          SetLength(TempI, Length(TempI) + 1);
          TempI[K]:= Temp[0].TIA[J][I];
          Inc(K);
        end;

      For I:= 0 To H do
        For J:= 0 To W do
          DrawATPABitmapEx(BMP, Temp[0].TPA, TempI);

      DebugBitmap(BMP);
      FreeBitmap(BMP);
    end;

    begin
      setupSRL;
      GetTextBoxes;
    end.
    I am Ggzz..
    Hackintosher

  2. #2
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    T2DPointArrays aren't actually managed types. You used SetLength() on "Temp", but you need to go through "Temp" doing something like SetLength(Temp[i].TPA, Length);
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  3. #3
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    tried that as well as Temp.TPA[I].. didn't work either..
    I am Ggzz..
    Hackintosher

  4. #4
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    Can you do 'Temp.TPA[J][I]:= TP;'? Might you not have to do something like 'Temp.TPA[j][I][0] := TP;'? Considering you are setting a TPA equal to a TPoint? It doesn't seem like you are taking advantage of the second dimension of your array. Maybe you just need a TPointArray?
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    It seems to me that you're only setting the length of the first dimension. Try this:
    Simba Code:
    {$I SRL/srl.Simba}
      {$I SRL/SRL/Misc/Debug.Simba}

    type
      TPAC = record
        TPA: T2DPointArray;
        TIA: T2DIntegerArray;
      end;

    Function GetTPACBox(B: TBox): TPAC;
    var
      Temp: TPAC;
      TP: TPoint;
      I, J, W, H: Integer;
    begin
      W:= B.X2 - B.X1;
      H:= B.Y2 - B.Y1;

      For I:= 0 To H do
        For J:= 0 To W do
        begin
          SetLength(Temp.TPA, Length(Temp.TPA) + 1);
          SetLength(Temp.TPA[J], Length(Temp.TPA[J]) + 1);
          TP:= Point(B.X1 + J, B.Y1 + I);
          Temp.TPA[J][I]:= TP;

          SetLength(Temp.TIA, Length(Temp.TIA) + 1);
          SetLength(Temp.TIA[J], Length(Temp.TIA[J]) + 1);
          Temp.TIA[J][I]:= GetColor(TP.X, TP.Y);
        end;
      Result:= Temp;
    end;

    Procedure GetTextBoxes;
    var
      Temp: Array of TPAC;
      B: TBox;
      I, J, K, BMP, W, H: Integer;
      TempI: TIntegerArray;
    begin
      B:= IntToBox(5, 5, 225, 20);
      SetLength(Temp, 4);
      Temp[0]:= GetTPACBox(B);
      MakeCompass('E');
      Temp[1]:= GetTPACBox(B);
      MakeCompass('S');
      Temp[2]:= GetTPACBox(B);
      MakeCompass('W');
      Temp[3]:= GetTPACBox(B);

      W:= B.X2 - B.X1;
      H:= B.Y2 - B.Y1;

      For I:= 0 To H do
        For I:= 0 To W do
          if ((Temp[0].TIA[J][I] <> Temp[1].TIA[J][I]) or (Temp[0].TIA[J][I] <> Temp[2].TIA[J][I]) or (Temp[0].TIA[J][I] <> Temp[3].TIA[J][I])) then
          begin
            Temp[0].TIA[J][I]:= 0;
            Temp[1].TIA[J][I]:= 0;
            Temp[2].TIA[J][I]:= 0;
            Temp[3].TIA[J][I]:= 0;
          end;

      BMP:= CreateBitmap(W, H);

      K:= 0;
      For I:= 0 To H do
        For J:= 0 To W do
        begin
          SetLength(TempI, Length(TempI) + 1);
          TempI[K]:= Temp[0].TIA[J][I];
          Inc(K);
        end;

      For I:= 0 To H do
        For J:= 0 To W do
          DrawATPABitmapEx(BMP, Temp[0].TPA, TempI);

      DebugBitmap(BMP);
      FreeBitmap(BMP);
    end;

    begin
      setupSRL;
      GetTextBoxes;
    end.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    That works Sex.. Except now my output looks like:


    [[(0, 0)]]
    [[(5, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(10, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(10, 5)], [(11, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(10, 5)], [(11, 5)], [(12, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(10, 5)], [(11, 5)], [(12, 5)], [(13, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(10, 5)], [(11, 5)], [(12, 5)], [(13, 5)], [(14, 5)], [(0, 0)]]
    [[(5, 5)], [(6, 5)], [(7, 5)], [(8, 5)], [(9, 5)], [(10, 5)], [(11, 5)], [(12, 5)], [(13, 5)], [(14, 5)], [(15, 5)], [(0, 0)]]


    When they should all really be the same length..
    It's supposed to go horizontally first, fill up then go down one, reset and fill up again.. and continue.. Doesn't do that.

    I'm using
    Simba Code:
    Function GetTPACBox(B: TBox): TPAC;
    var
      Temp: TPAC;
      TP: TPoint;
      I, J, W, H: Integer;
    begin
      W:= B.X2 - B.X1;
      H:= B.Y2 - B.Y1;
      MouseSpeed:= 500;

      For I:= 0 To H do
      begin
        For J:= 0 To W do
        begin
          SetLength(Temp.TPA, Length(Temp.TPA) + 1);
          SetLength(Temp.TPA[J], Length(Temp.TPA[J]) + 1);

          writeln(Temp.TPA);
          TP:= Point(B.X1 + J, B.Y1 + I);
          Temp.TPA[J][I]:= TP;

          MMouse(Temp.TPA[J][I].X, Temp.TPA[J][I].Y, 0, 0);

          SetLength(Temp.TIA, Length(Temp.TIA) + 1);
          SetLength(Temp.TIA[J], Length(Temp.TIA[J]) + 1);
          Temp.TIA[J][I]:= GetColor(TP.X, TP.Y);
        end;
        J:= 0;
        writeln('New Row');
        //SetLength(Temp.TPA[I], Length(Temp.TPA[I]) + 1);
        //SetLength(Temp.TIA[I], Length(Temp.TIA[I]) + 1);
      end;

      Result:= Temp;
    end;
    I am Ggzz..
    Hackintosher

Thread Information

Users Browsing this Thread

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

Posting Permissions

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