Recent

Author Topic: IFOPT and MObjPFC & MDelphi [SOLVED]  (Read 855 times)

DelphiDinosaur

  • New Member
  • *
  • Posts: 25
IFOPT and MObjPFC & MDelphi [SOLVED]
« on: September 01, 2025, 03:56:18 pm »
I have code that's shared between projects, some compile with the Object Pascal (MObjFPC) syntax mode, other use the Delphi (MDelphi) syntax mode as they use older shared Delphi 6 code.

Is there a way of using $IFOPT to toggle code between the two syntax models?

I need this to toggle between event assignment methods:
e.g.
Code: Pascal  [Select][+][-]
  1. AButton: TButton;
  2. {$IFOPT MDelphi}
  3. AButton.OnClick := MyOnClickHandler;
  4. {$ELSE}
  5. AButton.OnClick := @MyOnClickHandler;
  6. {$ENDIF}
  7.  



DD.
« Last Edit: September 01, 2025, 04:06:22 pm by DelphiDinosaur »

AlexTP

  • Hero Member
  • *****
  • Posts: 2696
    • UVviewsoft
Re: IFOPT and MObjPFC & MDelphi
« Reply #1 on: September 01, 2025, 03:58:29 pm »
Answer from AI Mistral:

To check the syntax mode, you should use $IFDEF with the predefined symbols FPC and DELPHI, or more specifically, FPC_OBJFPC for Object Pascal mode and FPC_DELPHI for Delphi mode.

DelphiDinosaur

  • New Member
  • *
  • Posts: 25
Re: IFOPT and MObjPFC & MDelphi
« Reply #2 on: September 01, 2025, 04:05:43 pm »
Thanks for the help. This works nicely:
Code: Pascal  [Select][+][-]
  1. {$IFDEF FPC_OBJFPC}
  2. AButton.OnClick := @MyOnClickHandler;
  3. {$ELSE}
  4. AButton.OnClick := MyOnClickHandler;
  5. {$ENDIF}
  6.  

I'd assumed it would work along the same lines as {IFOPT D+} for debug mode...

Thaddy

  • Hero Member
  • *****
  • Posts: 18924
  • Glad to be alive.
Re: IFOPT and MObjPFC & MDelphi [SOLVED]
« Reply #3 on: September 01, 2025, 04:23:37 pm »
Better to reverse it:
Code: Pascal  [Select][+][-]
  1. {$if defined(FPC_DELPHI) or defined(FPC_TP)}
  2.   writeln('Mode delphi');
  3. {$elseif defined(FPC_OBJFPC)}
  4.   writeln('Mode ObjFpc');
  5. {$elseif defined(FPC_FPC)}
  6.   writeln('Mode FPC');
  7. {$ifend}
  8.  
That is because Delphi mode is the exception, Almost all other modes use the @. Explicit Pointer dereferences
(Except mode FPC_TP)
« Last Edit: September 01, 2025, 05:15:04 pm by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

 

TinyPortal © 2005-2018