[Lazarus] Conditional compilation depending on Lazarus version?

Sven Barth pascaldragon at googlemail.com
Sat Mar 24 20:59:20 CET 2012


On 24.03.2012 20:46, Mark Morgan Lloyd wrote:
> Sven Barth wrote:
>> On 24.03.2012 19:35, Mark Morgan Lloyd wrote:
>
>>> As a variation of the latter, am I correct in saying that ifdef can't be
>>> used to check whether a function or procedure is implemented in some
>>> imported unit?
>>>
>>
>> $ifdef does only work with defines (those done with -dXXX or {$define
>> ...}), but not with identifiers/symbols (lcl_fullversion is a symbol).
>> If you want to check for the existance of a symbol you need to use this:
>>
>> {$if declared(lcl_fullversion) }
>> // code that should work with any version that defines lcl_fullversion
>> {$endif}
>> // Note: if you need Delphi compatibility you need to use {$ifend}
>> instead of {$endif} here
>
> Ah /ha/! So in other words I can use something like
>
> {$if declared(SerGetRI) }
> WriteLn('Has SerGetRI');
> {$endif }
>
> {$if declared(SerGetCD) }
> WriteLn('Has SerGetCD');
> {$endif }
>
> to check whether the updated serial.pp that I attached to bug 18946 is
> actually available, rather than having to scratch around looking for it
> when I don't actually need to monitor CD.
>

Yes, that should work that way.

Regards,
Sven




More information about the Lazarus mailing list