Is it possible to define more than one conditional in one {$IFDEF} directive ?
I would like to have syntax like this:
{$IFDEF Condition1 OR Condition2} DoSomething; {$ENDIF}
{$IFDEF Condition1 AND Condition2} DoSomethingElse; {$ENDIF}
Thanks
Is it possible to define more than one conditional in one {$IFDEF} directive ?
I would like to have syntax like this:
{$IFDEF Condition1 OR Condition2} DoSomething; {$ENDIF}
{$IFDEF Condition1 AND Condition2} DoSomethingElse; {$ENDIF}
Thanks
You would need to use $IF
instead:
{$IF Defined(Condition1) or Defined(Condition2)}
DoSomething;
{$IFEND}
{$ENDIF}
instead of {$IFEND}
–
Waylen In case you have to support old Delphis (without the support for the $IF metadirective), you can use one simple and one ugly workaround:
//AND
{$IFDEF Cond1}{$IFDEF Cond2}DoSomething{$ENDIF}{$ENDIF}
//OR
{$UNDEF Cond1OrCond2}
{$IFDEF Cond1}{$DEFINE Cond1OrCond2}{$ENDIF}
{$IFDEF Cond2}{$DEFINE Cond1OrCond2}{$ENDIF}
{$IFDEF Cond1OrCond2}DoSomething{$ENDIF}
If you are repeating the test more than once, first case should be rewritten as follows.
{$UNDEF Cond1AndCond2}
{$IFDEF Cond1}{$IFDEF Cond2}{$DEFINE Cond1AndCond2{$ENDIF}{$ENDIF}
{$IFDEF Cond1AndCond2}DoSomething{$ENDIF}
hey try this from the embarcadero.com
begin
...
{$IF Defined(MY_DEFINE) and (LibVersion > 2.0) }
Writeln(1);
{$ELSE}
Writeln(2);
...
{$IFEND}
end;
© 2022 - 2024 — McMap. All rights reserved.