SRL Archive - OSR Help

Lazarus doesn't know "Array of Integer"


marpis

2010-12-15 15:40:13

WTF?
[pascal]
function Galileo_MakeColorBoxEx(bmp, x1, y1, sidelength: integer): Array of integer; register;
[/pascal]

–>


GalileoProjekti(15,68) Error: Type identifier expected
GalileoProjekti(15,68) Fatal: Syntax error, ";" expected but "ARRAY" found

I'm so pissed with this, I have written an awesome color positioning system, and the only problem now is that I can't get it into a dll.

Wizzup?

2010-12-15 15:43:20

It does, but it doesn't want open types in procedure definitions. Use TIntegerArray, or define it yourself.

marpis

2010-12-15 15:49:58

How about 3D integer arrays?

Also:
SetLength(Result, 3);
gives me
GalileoProjekti(21,23) Error: Type mismatch

Wizzup?

2010-12-15 15:57:19


type
TIntegerArray = Array of Integer;
TIntegerArrayArray = Array of Array of Integer;

function foo(bar:integer):TIntegerArray;
function foo2(bar2:integer): TIntegerArrayArray;

marpis

2010-12-15 17:01:12

Woooot?

function Galileo_MakeColorBoxEx(bmp, x1, y1, sidelength: integer): TIntegerArray; register; //[0]=Red [1]=Green [2]=Blue
var
x, y: integer;
R, G, B: integer;
begin
SetLength(Result, 3); // <--- probelm

for x := x1 to (x1 + sidelength) do
for y := y1 to (y1 + sidelength) do
begin
try
ColorToRGB(bmp.GetPixel(x, y)), R, G, B);
Result[0] := Result[0] + R;
Result[1] := Result[1] + G;
Result[2] := Result[2] + B;
except
writeln('ColorToRGB exception: '+inttostr(x)+', '+inttostr(y));
end;
end;
end;


GalileoProjekti(21,23) Error: Type mismatch


Wizzup?

2010-12-15 17:02:31

Did you define the types?

marpis

2010-12-15 17:06:59

From: Wizzup?
Did you define the types?


Nope, it doesn't seem to have a problem with TIntegerArray.
Doesn't say "unknown identifier" about the line
function Galileo_MakeColorBoxEx(bmp, x1, y1, sidelength: integer): TIntegerArray; register;

marpis

2010-12-15 17:08:03

SOLVED! :)
Defining types helped! Thanks!

New problem:
How do I get a pixel from bitmap? Not a TBitmap, an Integer bitmap?

Wizzup?

2010-12-15 17:08:33

I thought it was type mismatch previously??? And why don't you just define the types as that will take care of your unknown identifier problem?

E: I see it works. Pixel from a bitmap. You'll be best of passing the TMufasaBitmap I think. I'll have to think about this. For now you can just get the data as array and pass that to the dll, no?

marpis

2010-12-15 17:16:25

From: Wizzup?
I thought it was type mismatch previously??? And why don't you just define the types as that will take care of your unknown identifier problem?


From: marpis
SOLVED! :)
Defining types helped! Thanks!

New problem:
How do I get a pixel from bitmap? Not a TBitmap, an Integer bitmap?


asdf

Wizzup?

2010-12-15 17:17:14

Edited post already.

marpis

2010-12-15 17:48:05

NEW PROBLEM

Now I try to only do the math parts with the dll, so I leave the bitmaps to Simba.
This is the final code:

library Galileo;

{$mode objfpc}{$H+}

uses
Classes, sysutils;


type
TIntegerArray = Array of Integer;
T3DIntegerArray = Array of Array of Array of Integer;


function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean; register;
begin
if (B1[0] >= Round(B2[0]*(1-tol))) and (B1[0] <= Round(B2[0]*(1+tol))) then
if (B1[1] >= Round(B2[1]*(1-tol))) and (B1[1] <= Round(B2[1]*(1+tol))) then
if (B1[2] >= Round(B2[2]*(1-tol))) and (B1[2] <= Round(B2[2]*(1+tol))) then
begin
Result := True;
Exit;
end;
end;


function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; SideLength: integer; tol: extended; MaxFails: integer): TPoint; register;
var
x, y, HighX, HighY: integer;
xx, yy: integer;
Matching: integer;
begin
Result := Point(-1, -1);

HighX := High(LargeMap);
HighY := High(LargeMap[0]);

for x := 0 to HighX do
for y := 0 to HighY do
if Galileo_ColorBoxesMatch(LargeMap[x][y], SmallMap[0][0], tol) then
begin
Matching := 0;
try
// top left matches, let's compare the others
for xx := 0 to 19 do
for yy := 0 to 19 do
if Galileo_ColorBoxesMatch(LargeMap[x+xx][y+yy], SmallMap[xx][yy], tol) then
Inc(Matching);

//writeln('matching: '+inttostr(matching));
if Matching >= (400 - MaxFails) then // 20*20 = 400
begin
Result.X := (x + 10)*Sidelength; // +10 cause we want the center
Result.Y := (y + 10)*Sidelength;
Exit;
end;
except
end;
end;
end;

function Galileo_FindMapInMapLoop(SmallMap, LargeMap: T3DIntegerArray; sidelength: integer; mintol, maxtol, tolstep: extended; minfails, maxfails, failsstep: integer): TPoint; register;
var
fails: integer;
tol: extended;
begin
tol := mintol;
while (tol < maxtol) do
begin
fails := minfails;
while (fails < maxfails) do
begin
Result := Galileo_FindMapInMapExx(LargeMap, SmallMap, sidelength, tol, fails);
if (Result.X > 0) and (Result.Y > 0) then
Exit;
fails := fails + failsstep;
end;
tol := tol + tolstep;
end;
end;

//////
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 3;
end;

function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
begin
Result := 0;
case x of
0..2 : Result := 1;
end;
end;

function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @Galileo_ColorBoxesMatch;
StrPCopy(ProcDef, 'Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
end;
1:
begin
ProcAddr := @Galileo_FindMapInMapExx;
StrPCopy(ProcDef, 'Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; SideLength: integer; tol: extended; MaxFails: integer): TPoint;');
end;
2:
begin
ProcAddr := @Galileo_FindMapInMapLoop;
StrPCopy(ProcDef, 'function Galileo_FindMapInMapLoop(SmallMap, LargeMap: T3DIntegerArray; sidelength: integer; mintol, maxtol, tolstep: extended; minfails, maxfails, failsstep: integer): TPoint;');
end;
else
x := -1;
end;
Result := x;
end;


exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;


begin
end.

And it compiles & builds successfully, but when I try to load the plugin in Simba, it says (again)


[Error] (2:1): Unable to register function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean; at line 1

Damn I'm so close but yet so far!

i luffs yeww

2010-12-15 18:00:06

Export it, I think? You're only exporting GetFunctionCount, GetFunctionInfo, and GetFunctionCallingConv. You need to export them all, I think?

Shuttleu

2010-12-15 18:23:30

try this
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @Galileo_ColorBoxesMatch;
StrPCopy(ProcDef, 'function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
end;
1:
begin
ProcAddr := @Galileo_FindMapInMapExx;
StrPCopy(ProcDef, 'function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; SideLength: integer; tol: extended; MaxFails: integer): TPoint;');
end;
2:
begin
ProcAddr := @Galileo_FindMapInMapLoop;
StrPCopy(ProcDef, 'function Galileo_FindMapInMapLoop(SmallMap, LargeMap: T3DIntegerArray; sidelength: integer; mintol, maxtol, tolstep: extended; minfails, maxfails, failsstep: integer): TPoint;');
end;
else
x := -1;
end;
Result := x;
end;

~shut

marpis

2010-12-15 19:15:18

From: Shuttleu
try this
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @Galileo_ColorBoxesMatch;
StrPCopy(ProcDef, 'function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
end;
1:
begin
ProcAddr := @Galileo_FindMapInMapExx;
StrPCopy(ProcDef, 'function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; SideLength: integer; tol: extended; MaxFails: integer): TPoint;');
end;
2:
begin
ProcAddr := @Galileo_FindMapInMapLoop;
StrPCopy(ProcDef, 'function Galileo_FindMapInMapLoop(SmallMap, LargeMap: T3DIntegerArray; sidelength: integer; mintol, maxtol, tolstep: extended; minfails, maxfails, failsstep: integer): TPoint;');
end;
else
x := -1;
end;
Result := x;
end;

~shut


What's different there?

Shuttleu

2010-12-16 15:29:40

From: marpis
What's different there?


you forgot to put "function " in front of Galileo_ColorBoxesMatch and FindMapInMapExx

did it work btw?

~shut

marpis

2010-12-17 02:32:01

From: Shuttleu
you forgot to put "function " in front of Galileo_ColorBoxesMatch and FindMapInMapExx

did it work btw?

~shut


Thanks a lot, that helped :)

BUT NEW PROBLEM:


It compiles and builds nicely, but now Simba says

[Error] (2:1): Unable to register function function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; var foundX, foundY: integer; SideLength: integer; tol: extended; MaxFails: integer): boolean; at line 1

I guess that it because the type T3DIntegerArray for some reason.

Shuttleu

2010-12-17 05:48:18

From: marpis
Thanks a lot, that helped :)

BUT NEW PROBLEM:


It compiles and builds nicely, but now Simba says

[Error] (2:1): Unable to register function function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; var foundX, foundY: integer; SideLength: integer; tol: extended; MaxFails: integer): boolean; at line 1

I guess that it because the type T3DIntegerArray for some reason.


the return type for Galileo_FindMapInMapExx is TPoint not Boolean
did you accidently type Boolean instead of TPoint
maybe you need to define the type TPoint?

~shut

marpis

2010-12-17 08:45:29

From: Shuttleu
the return type for Galileo_FindMapInMapExx is TPoint not Boolean
did you accidently type Boolean instead of TPoint
maybe you need to define the type TPoint?

~shut


I did define TPoint, and I changed the result to boolean cause I thought that the result type TPoint was causing trouble.

Wizzup?

2010-12-17 08:55:29

From: marpis
It compiles and builds nicely, but now Simba says

[Error] (2:1): Unable to register function function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; var foundX, foundY: integer; SideLength: integer; tol: extended; MaxFails: integer): boolean; at line 1

I guess that it because the type T3DIntegerArray for some reason.


Yes. We need to add support to exporting types in simba plugin loader. I think in the string you can try: array of array of array of integer; It'll probably work. (But we really need to add exporting types to simba plugin loader.

marpis

2010-12-17 11:09:36

From: Wizzup?
Yes. We need to add support to exporting types in simba plugin loader. I think in the string you can try: array of array of array of integer; It'll probably work. (But we really need to add exporting types to simba plugin loader.


Tried that, still getting

[Error] (2:1): Unable to register function function Galileo_FindMapInMapExx(LargeMap, SmallMap: array of array of array of integer; var foundX, foundY: integer; SideLength: integer; tol: extended; MaxFails: integer): boolean; at line 1