Forum > General

are compound conditional directives supposed to work ?

(1/4) > >>

440bx:
Hello,

I was reading the following wiki page
http://wiki.freepascal.org/Conditional_compilation
which as an example shows:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IFDEF BLUE AND $IFDEF RED} Form1.Color := clYellow; {$ENDIF}
I needed something like that but using or instead of "and".  I tried using "OR" in the conditional and it didn't work (it is what it is.) 

My question is: was it supposed to work or is the Wiki page "not quite right" ?  better yet, is there some way to make such a construct work ? (without "helper" conditions and nested ifs)

Thanks. 

Full example below:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC}  //// from://// http://wiki.freepascal.org/Conditional_compilation//// {$IFDEF BLUE AND $IFDEF RED} Form1.Color := clYellow; {$ENDIF}   program ConditionalDirectives; //{$define abc0123456789}{$define xyz0123456789} uses  windows   {$ifdef abc0123456789 or $ifdef xyz0123456789}  ,  sysutils  {$endif}  ; begin  // this works as expected   {$ifdef abc0123456789}    writeln('abc is defined');  {$endif}   // this works as expected   {$ifdef xyz0123456789}    writeln('xyz is defined');  {$endif}   //  but this does not work as the wiki page implies it should  //  the "or" seems to be ignored by the compiler   {$ifdef abc0123456789 or $ifdef xyz0123456789}    writeln('either abc or xyz is defined');     writeln('IntToHex 16 ', IntToHex(16, 6));  {$endif}end. 

Blaazen:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$if defined(abc0123456789) or defined(xyz0123456789)}...code...{$endif}

440bx:
That worked. Thank you Blaazen. 

engkin:
Also:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  {$IFNDEF BLUE AND $IFNDEF RED}  WriteLn('not Blue nor Red');  {$ELSE}  WriteLn('Blue or Red');  {$ENDIF}

440bx:

--- Quote from: engkin on November 10, 2018, 03:12:01 am ---Also:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  {$IFNDEF BLUE AND $IFNDEF RED}  WriteLn('not Blue nor Red');  {$ELSE}  WriteLn('Blue or Red');  {$ENDIF}
--- End quote ---

@Engkin

I'm under the impression that construct doesn't always work (of course, I could be mistaken).  I get that impression because in the example I posted,
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- //{$define abc0123456789}{$define xyz0123456789} { some code which doesn't matter here }    {$ifdef abc0123456789 or $ifdef xyz0123456789}    writeln('either abc or xyz is defined');     writeln('IntToHex 16 ', IntToHex(16, 6));  {$endif}end.  the writeln statements are not executed in spite of the fact that xyz0123456789 is defined.  In the same vein, the sysutils unit (see the original example) is not included.   When using that construction, it appears that the condition after the or is not evaluated and if the first condition is false then the entire condition is false even though it should be true because of the or and second condition being true.

Maybe I'm missing something... ?

Navigation

[0] Message Index

[#] Next page

Go to full version