Predefined symbol to select between Lazarus and Delphi
Asked Answered
W

2

8

I am looking for a predefined symbol to write a code like that:

{$IFDEF LAZARUS}
// code compiles by fpc/lazarus
{$ELSE}
// code compiles by delphi
{$ENDIF}
Womenfolk answered 30/8, 2012 at 15:8 Comment(0)
C
14

Use FPC             

{$IFDEF FPC}
Cupellation answered 30/8, 2012 at 15:9 Comment(12)
FPC is defined by the compiler rather than the IDE. So it will be correct for all IDEs that use FPC as their compiler.Cupellation
Yes I don't think there's a directive to detect the IDE at all. After all, the IDE is just an enriched Notepad to type your code in.Cubeb
IDE itself could possibly define a conditional symbol, and store it in compiler options.Womenfolk
What does it matter which IDE is invoking the compiler?Cupellation
Maybe he thinks IDE = widgets library, hence Lazarus = LCL.Concomitance
I also think the code should check for both FPC and Delphi. There is GNU Pascal, there is Virtual Pascal, OpenSibil, MIDlet Pascal and who knows what else, even Oxygene is compatible to some point. I am certain that both FPC and DELPHI should be checked. Maybe they should be checked once in the header, and if none defined then abort compilation due to non-supported compiler. But at lease once Delphi presence should be ensuredConcomitance
I am porting a unit test project to Lazarus and need ex to use different unit names in uses clause. DUnit implementation is specific to IDE.Womenfolk
I am currently experimenting with built-in Lazarus GUI testrunnerWomenfolk
@Arioch: starting in XE2 (or maybe XE, I forget which), the Delphi compiler started defining the DCC conditional for itself. Prior to that, there was no defining conditional to identify the Delphi compiler, except indirectly via the version-specific VERxxx conditionals.Chandelle
@GolezTrol: not so simple as in Delphi you may have some code related to the IDE itself, ie: when you use ToolsAPI.Nominal
@Nominal That is still compiled using the Delphi compiler (for the Delphi IDE) or by FreePascal if you compile (for) Lazarus.Cubeb
Maybe in combination with a define for designtime parts of componentsAlanson
A
1

For GUI applications afaik the "LCL" symbol is defined inside Lazarus projects. In this case it probably won't matter.

In general, for bigger codebases, I would avoid having too much ifdef FPC/LCL and ifdef in your sourcecode though. It makes adding an exception or other version harder.

Use a system like JCL and Zeos(7) are using, where you give most differences an own name (like "USE_FPCUNIT" or "USE_DUNIT") and link these to versions in a central includefile.

For a short treatise on the subject see http://www.stack.nl/~marcov/porting.pdf (chapter 2)

P.s. I would consider Pocketstudio, TP,GPC,VP and WDSybil (and whatever I forgot) dead for most practical purposes and the bytecode variants Canterbury Pascal/Component Pascal/Oxygene/Prism/Delphi.NET incompatible (most are more Oberon than Pascal anyway). That pretty much leaves Delphi, Kylix and FPC to worry about.

Alanson answered 6/9, 2012 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.