Results 1 to 21 of 21

Thread: Lazarus doesn't know "Array of Integer"

  1. #1
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default Lazarus doesn't know "Array of Integer"

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

    -->

    Code:
    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.

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

    Default

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



    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)

  3. #3
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    How about 3D integer arrays?

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

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

    Default

    pascal Code:
    type
    TIntegerArray = Array of Integer;
    TIntegerArrayArray = Array of Array of Integer;

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



    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
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Woooot?
    Code:
    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;
    Code:
    GalileoProjekti(21,23) Error: Type mismatch

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

    Default

    Did you define the types?



    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)

  7. #7
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    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;

  8. #8
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    SOLVED!
    Defining types helped! Thanks!

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

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

    Default

    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?
    Last edited by Wizzup?; 12-15-2010 at 10:16 PM.



    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)

  10. #10
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    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?
    Quote Originally Posted by marpis View Post
    SOLVED!
    Defining types helped! Thanks!

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

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

    Default

    Edited post already.



    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)

  12. #12
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    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:
    Simba 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)

    Code:
    [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!

  13. #13
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

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

  14. #14
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    try this
    Simba Code:
    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

  15. #15
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Shuttleu View Post
    try this
    Simba Code:
    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?

  16. #16
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  17. #17
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Shuttleu View Post
    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
    Code:
    [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.

  18. #18
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    Thanks a lot, that helped

    BUT NEW PROBLEM:


    It compiles and builds nicely, but now Simba says
    Code:
    [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

  19. #19
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Shuttleu View Post
    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.

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

    Default

    Quote Originally Posted by marpis View Post
    It compiles and builds nicely, but now Simba says
    Code:
    [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.



    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)

  21. #21
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    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
    Code:
    [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

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
  •