On 30 Jun 2015, at 20:54, silvioprog wrote:

> 
> The code above compiles fine in Delphi (tested in XE 7), but in FPC I got the 
> following compiling error:
> 
> Unit1.pas(46,14) Error: Incompatible types: got "<class method type of 
> procedure({Open} Array Of Byte;out AnsiString) of object;Register>" expected 
> "<procedure variable type of procedure({Open} Array Of Byte;out 
> AnsiString);Register>".
> 
> Is this a bug or I need to enable some switch?
> 

Back in 2012 I had a similar issue. Original message can be found here: 
http://lists.freepascal.org/pipermail/fpc-pascal/2012-December/035921.html

I fixed it by declaring a type that includes the hidden parameter mentioned in 
that thread, so in your case:

    Type
                TMyProc = procedure(aClassType: TClass; ABytes: array of Byte; 
out AOutput: AnsiString);

the invocation then becomes
        FMyProc(ClassType, [65, 66, 67], S);

instead of 
        FMyProc([65, 66, 67], S);

And, of course, the assignment to FMyProc becomes more verbose and less 
type-safe: 
        FMyProc := TMyProc(Pointer(@DoMyProc));

NOTE: This is a hack. It is not documented anywhere, but i have used this 
approach since late 2012 without any problems so far. Better be careful and 
write a small sanity test that checks correct operation every time you use a 
new compiler.


--
Ewald

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to