11

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?

6
  • "a lack of a common (and portable) synchronizing mechanism" - FreePascal mimics many of Delphi's core classes, include TThread and its Synchronize() method: FreePascal Wiki | Multithreaded Application Tutorial | The TThread Class Commented Oct 22, 2015 at 22:20
  • @RemyLebeau I needed a non-blocking synchronisation mechanism and I got it with (the thread-safe) Application.QueueAsyncCall in Lazarus and PostMessage to an invisible Window (via AllocateHWnd) in Delphi. Of course, I used the TThread class, but Synchronize was not helpful in my case because of its rendezvous feature. Thanks anyway :) Commented Oct 23, 2015 at 7:31
  • TThread also has an asynchronous Queue() method. Commented Oct 23, 2015 at 17:30
  • @RemyLebeau I'm afraid there is no Queue method in Delphi 4, that I have to use (I'm not sure, I've no D4 or its docs at hand now). So I better remove the sidenote from the question or be more specific about the versions I'm using? Commented Oct 23, 2015 at 20:06
  • You did not say which Delphi/FreePascal version you are using. No, Queue() does not exist in D4. FreePascal mimics D7. Commented Oct 24, 2015 at 0:26

1 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That's the kind of solution I was hoping for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.