Recent

Author Topic: Compiler directive - what does it mean?  (Read 1002 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
Compiler directive - what does it mean?
« on: January 30, 2023, 01:04:14 pm »
This seems to have written some tool into my source

Code: Text  [Select][+][-]
  1. {$IFnDEF FPC}
  2.   {$R *.lfm}
  3. {$ELSE}
  4.   {$R *.lfm}
  5. {$ENDIF}  

What may happen, if I delete them?
I suppose, my form may be gone? What will happen, if I delete just one part and - which one?

Thanks

Paolo

  • Hero Member
  • *****
  • Posts: 508
Re: Compiler directive - what does it mean?
« Reply #1 on: January 30, 2023, 01:18:18 pm »
it shloud be something like

Code: Pascal  [Select][+][-]
  1. {$IFnDEF FPC}
  2.   {$R *.dfm}  //<---- dfm
  3. {$ELSE}
  4.   {$R *.lfm}
  5. {$ENDIF}
  6.  

otherwise it is a no sense... This code is tipically come from Delphi transltation to FPC

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2049
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Compiler directive - what does it mean?
« Reply #2 on: January 30, 2023, 01:20:14 pm »
Fully correct, the way your original code is shown it makes absolute no sense, do it like Paole wrote and you still can open it in Delphi.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Compiler directive - what does it mean?
« Reply #3 on: January 30, 2023, 04:30:20 pm »
thank you for your replies.

What do they mean for me?
What may I do with those items?
May I delete all of them or just one?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2049
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Compiler directive - what does it mean?
« Reply #4 on: January 30, 2023, 04:38:26 pm »
When you not need it for Delphi ->
Code: Pascal  [Select][+][-]
  1.   {$R *.lfm}
Thats all you need.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: Compiler directive - what does it mean?
« Reply #5 on: January 30, 2023, 04:52:14 pm »
{$IFDEF FPC} means: "if the symbol "FPC" is defined" then use the following text until the {$ELSE} or {$ENDIF. The text between {$ELSE} and {$ENDIF} is ignored when FPC is defined. In Delphi, for example, the define FPC does not exist, and Delphi ignores the part between {$IFDEF FPC} and {$ELSE} and uses the part between {$ELSE} and {$ENDIF}. This way you can use the same unit in FPC and Delphi.

{$IFNDEF FPC} has the same meaning, but with inverted logic: "if the symbol "FPC" is NOT defined"...

{$R ...} tells the IDE to link the resource files (resource = "R") specified.

If you only work with Lazarus and NEVER will use the same code in Delphi you can delete all lines in the range in which the define FPC is not active.

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Compiler directive - what does it mean?
« Reply #6 on: January 30, 2023, 06:33:23 pm »
it shloud be something like

Code: Pascal  [Select][+][-]
  1. {$IFnDEF FPC}
  2.   {$R *.dfm}  //<---- dfm
  3. {$ELSE}
  4.   {$R *.lfm}
  5. {$ENDIF}
  6.  

otherwise it is a no sense... This code is tipically come from Delphi transltation to FPC

Code: Pascal  [Select][+][-]
  1. {$IFnDEF FPC}
  2.   {$R *.dfm}  //<---- dfm
  3. {$ELSE}
  4.   {$IFDEF LCL}  // <---- lcl widget-set
  5.     {$R *.lfm}
  6.   {$ENDIF}
  7. {$ENDIF}
  8.  

 ;)
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Compiler directive - what does it mean?
« Reply #7 on: January 30, 2023, 07:08:16 pm »
Thanks.

So my idea is, there must be a
Code: Pascal  [Select][+][-]
  1. {$R *.lfm}  

(at least it does not work any more without it)

=> I never will turn back to Delphi, I am glad, to have left it behind.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Compiler directive - what does it mean?
« Reply #8 on: January 30, 2023, 07:30:46 pm »
Well, for console apps, .lfm files are irrelevant, so you don't need any
Code: Pascal  [Select][+][-]
  1. {$R *.lfm}
for those.

Even for GUI apps, you only need that resource directive in form files. It is not needed in other non-form files (such as a GUI's .lpr file).

If you use Lazarus as your code editor, you rarely need to even think about  that directive anyway, since Lazarus' management of the project ensures it is inserted automatically, and only where needed.

 

TinyPortal © 2005-2018