Log in

View Full Version : Out Of Range T2D...



Brandon
02-01-2012, 12:50 AM
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..


{$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.

euphemism
02-01-2012, 02:12 AM
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);

Brandon
02-01-2012, 02:27 AM
tried that as well as Temp.TPA[I].. didn't work either..

euphemism
02-01-2012, 02:36 AM
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?

Sex
02-01-2012, 02:43 AM
It seems to me that you're only setting the length of the first dimension. Try this:{$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.

Brandon
02-01-2012, 03:18 AM
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

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;