Forum > FPC development

Compiler directive issue

(1/3) > >>

Pontiac:
According to:
http://lazarus-ccr.sourceforge.net/fpcdoc/prog/progsu29.html#x36-340001.1.29
and
http://lazarus-ccr.sourceforge.net/fpcdoc/prog/progap7.html#x323-323000G

I have the code:

--- 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 Application.MessageBox(pchar(HDDFile+' is in a read only state.  Do you wish to enable read/write mode?'),'File Attribute',MB_YESNO+MB_ICONQUESTION)={$IFDEF FPC}IDYES{$ELSE}ID_YES{$ENDIF} then
The problem I'm having is that the compiler thinks it should use ID_YES instead of IDYES.

This particular unit is currently shared between Delphi 2010 and FPC, as will a few others will be until I completely migrate over to FPC, but I'm kinda curious to why this is happening?

JuhaManninen:
Neither of the pages mentions Application.MessageBox. Why did you add {$IFDEF FPC} there?

Pontiac:
Major edit:

I'm not worried about application.messagebox, I'm wondering why the compiler is not honoring the {$IFDEF FPC}...{$ELSE}...{$ENDIF}.

While compiling under FPC, it should compile with IDYES (FPC constant) and not ID_YES (Delphi constant).  The FPC compile error comes back saying it doesn't know what ID_YES is.

rvk:
The unit lcltype has this:

--- 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";}};} ---  IDOK = 1;     ID_OK = IDOK;  IDCANCEL = 2; ID_CANCEL = IDCANCEL;  IDABORT = 3;  ID_ABORT = IDABORT;  IDRETRY = 4;  ID_RETRY = IDRETRY;  IDIGNORE = 5; ID_IGNORE = IDIGNORE;  IDYES = 6;    ID_YES = IDYES;  IDNO = 7;     ID_NO = IDNO;  IDCLOSE = 8;  ID_CLOSE = IDCLOSE;  IDHELP = 9;   ID_HELP = IDHELP; So can't you just use

--- 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";}};} ---uses Windows, {$IFDEF FPC} lcltype, {$ENDIF} ....etc
I see you also have MB_YESNO & MB_ICONQUESTION in there and those are also not defined by default in Lazarus. So if you include lcltype it will also solve those constants.


--- Quote ---This unit is being created specifically for compatibility with Delphi. It
should only be used for constants and type definitions that are included in
the Delphi Windows unit. This is only done for compatibiltiy.

--- End quote ---

As for your problem. For me it does recognize IDYES so maybe you have {$UNDEF FPC} somewhere in your code :) Try that line in a clean empty project.

Pontiac:
I don't know what my computer was drinking this morning when I posted this, but now things are working as expected after I left it alone for several hours.

Copy/paste of earlier from my thread;

--- 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 Application.MessageBox(pchar(HDDFile+' is in a read only state.  Do you wish to enable read/write mode?'),'File Attribute',MB_YESNO+MB_ICONQUESTION)={$IFDEF FPC}IDYES{$ELSE}ID_YES{$ENDIF} then
What I have now:

--- 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 Application.MessageBox(pchar(HDDFile+' is in a read only state.  Do you wish to enable read/write mode?'),'File Attribute',MB_YESNO+MB_ICONQUESTION)={$IFDEF FPC}IDYES{$ELSE}ID_YES{$ENDIF} then
Now it works fine.

The only thing I did was try and add the lcltype file, recompile to verify the suggestion by rvk, it worked.  I reverted the lcltype change, recompiled, and it worked.

... Computers these days. :P

EDITWAR:
@rvk - I've not used any UNDEFs ever anywhere.  I've only been actively using Laz/FPC for a couple of days, and this is the first unit I've had to convert so far.

Navigation

[0] Message Index

[#] Next page

Go to full version