Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event assignment syntax in different Object Pascal dialects

I'm working on a component that should be shared between Delphi and C++Builder, so I'm using Pascal as the lingua franca. Because I don't have Delphi on my computer at home, I first created the component in the Lazarus IDE. Now I "ported" it to Delphi and found an astonishing syntax problem:

This compiles with FPC (but not Delphi):

FSync.FSyncMethod := @SyncCheckInput;

This compiles with Delphi (but not FPC):

FSync.FSyncMethod := SyncCheckInput;

How can I share a unit between Lazarus and Delphi despite this syntactic divergence?

like image 552
Wolf Avatar asked Oct 22 '15 12:10

Wolf


1 Answers

Insert this at the beginning of your units:

{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}

This will instruct FreePascal to use the Delphi dialect to compile the unit. Delphi will ignore the {$MODE DELPHI} directive because FPC is not defined.

You can then use this

FSync.FSyncMethod := SyncCheckInput;

for setting events dynamically.

like image 54
Wosi Avatar answered Oct 04 '22 22:10

Wosi