May I ask about the syntax issue? Delphi supports anonymous functions, but FPC does not support this syntax?

TEnumImagePartProc = reference to procedure (const FileName:String;Stream : TImageFilePartInfo);

在fpc3.2.2中编译报错
Compilation error in fpc3.2.2

This doesn’t work?

TEnumImagePartProc = procedure (const FileName:String;Stream : TImageFilePartInfo);
var myproc : TEnumImagePartProcl
procedure aproc( const FileName:String;Stream : TImageFilePartInfo);
myproc := @aproc;

?

TCastleSoundChangeEvent = procedure (const Sender: TCastleSound; const Change: TSoundChange) of object;

FSound.InternalAddChangeNotification({$ifdef FPC}@{$endif}SoundChangeDuringPlayback);

I checked the castle engine and didn’t use this syntax. Forget it, I plan to rewrite it all in this way. Thank you very much for your guidance

For anonymous functions, you need to use FPC 3.3.1. That is, get FPC from the latest FPC “main” branch on GitLab. It is unstable FPC version (and changes every day), though in practice it almost always works smoothly, also with Castle Game Engine – we regularly test with this FPC. The easiest way to install this FPC is though FpcUpDeluxe.

The FPC 3.2.2 indeed doesn’t support anonymous functions, or (closely related) reference to ... types.

So it’s your choice whether to do more adjustments of your code to FPC 3.2.2 (without anonymous functions) or upgrade to FPC 3.1.1. In practice, it depends on how “badly” do you need to use anonymous functions – if avoiding them is trivial, then I’d advise to avoid them and stick to stable FPC 3.2.2. Unless your codebase uses them intensively, then upgrading to FPC 3.3.1 may be easier. Of course this advise will change once FPC will release version 3.4 and so stable FPC will have all you need :slight_smile:

I have updated our modern Pascal introduction to mention anonymous functions. See section " 8.3. Anonymous functions" there.

See also FPC forum post Feature announcement: Function References and Anonymous Functions , and all my examples of it: