Recent

Author Topic: Compiler directive issue  (Read 6601 times)

Pontiac

  • New Member
  • *
  • Posts: 20
Compiler directive issue
« on: November 12, 2015, 06:48:13 pm »
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  [Select][+][-]
  1. 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Compiler directive issue
« Reply #1 on: November 12, 2015, 09:39:32 pm »
Neither of the pages mentions Application.MessageBox. Why did you add {$IFDEF FPC} there?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Pontiac

  • New Member
  • *
  • Posts: 20
Re: Compiler directive issue
« Reply #2 on: November 12, 2015, 10:24:23 pm »
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.
« Last Edit: November 12, 2015, 10:30:39 pm by Pontiac »

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Compiler directive issue
« Reply #3 on: November 12, 2015, 10:30:35 pm »
The unit lcltype has this:
Code: Pascal  [Select][+][-]
  1.   IDOK = 1;     ID_OK = IDOK;
  2.   IDCANCEL = 2; ID_CANCEL = IDCANCEL;
  3.   IDABORT = 3;  ID_ABORT = IDABORT;
  4.   IDRETRY = 4;  ID_RETRY = IDRETRY;
  5.   IDIGNORE = 5; ID_IGNORE = IDIGNORE;
  6.   IDYES = 6;    ID_YES = IDYES;
  7.   IDNO = 7;     ID_NO = IDNO;
  8.   IDCLOSE = 8;  ID_CLOSE = IDCLOSE;
  9.   IDHELP = 9;   ID_HELP = IDHELP;
  10.  
So can't you just use
Code: Pascal  [Select][+][-]
  1. 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.

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.
« Last Edit: November 12, 2015, 10:37:58 pm by rvk »

Pontiac

  • New Member
  • *
  • Posts: 20
Re: Compiler directive issue
« Reply #4 on: November 12, 2015, 10:50:04 pm »
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  [Select][+][-]
  1. 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  [Select][+][-]
  1. 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.
« Last Edit: November 12, 2015, 10:52:57 pm by Pontiac »

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Compiler directive issue
« Reply #5 on: November 12, 2015, 10:53:11 pm »
I reverted the lcltype change, recompiled, and it worked.
I would still use the lcltype-method. It will save you a lot of {$IFDEF FPC}s in your code and all those IFDEFs only make your code more difficult to read.

You can remove all those {$IFDEF FPC} from your code after using lcltype.

Pontiac

  • New Member
  • *
  • Posts: 20
Re: Compiler directive issue
« Reply #6 on: November 14, 2015, 11:03:59 pm »
I came across something rather interesting with this issue.

Still, without using LCLType unit, I was running into this problem when I launched Lazarus from the shortcut on my desktop. 

I went to File> Open Recent> NameOfThisProject.lci.

I first noticed that the unit which my original line came from was in considered read only as far as Laz was concerned.  I checked the file permissions and no, it is not read only.  So then thought that maybe Laz was loading the wrong unit (Since it is in multiple locations) so deleted the others and just kept this one.  Using this method, the unit is not found (Yet exists in the directory).  So somehow it was loading up a version of this unit from somewhere else.  Ok!  Step in the right direction, but still doesn't answer the IFDEF FPC problem.

I closed down Laz, this time launched Laz via the .LCI file and voila the unit shows up as I last had it, and it is R/W.  Looking down at this unit, I see that NOW it thinks FPC is defined.

So when using the FILE> OPEN RECENT, is the directory not changed?  Am I loading up from some kind of directory (Probably my "Global Units/SQLite" directory), which THAT one was R/O.  Why when I launch IDE from the desktop, it doesn't think that FPC is defined?

I'm sorry about ignoring the suggestion of using the LCLType unit, but I need to know how this IDE works to use it effectively.  I'm not one of those developers that like to adhoc stuff like this when my usual routine is breaking down.  I have a very impulsive need to understand what is going on with this.  If I write applications ground up to absolutely remove Delphi from existing and new projects, I have to know where the IDE is getting its stuff, and I'm not seeing where yet, both for files AND for the compiler directives.

Edit: First thing I realized I was doing wrong.  I shouldn't be opening the LPI but the LPR.  Ok, cool.  However, when I load the LPR from the directory (Not desktop) the IDE again thinks that LAZ is not defined.

This project was started ENTIRELY within Lazarus, not Delphi.  The only thing that is Delphi related is the SQLite related units I've been using for a few years and don't quite want to let go of.

Time to pull out some text editors.
« Last Edit: November 14, 2015, 11:08:09 pm by Pontiac »

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Compiler directive issue
« Reply #7 on: November 14, 2015, 11:20:55 pm »
You're quite right in wanting to know why {$IFDEF FPC} doesn't work for you. Using lcltype is for later.

You mention a .lci file... did you mean .lpi.
(I don't know what .lci stands for)

But you also say you do it via File > Open Recent > project.???
I think that's not the correct way to open a project.
You should be using Project > Open Recent Project

It could be that your file was just opened as a unit in another project. You can check with what project you're working in the Project > Project inspector
So maybe the unit you opened with File > Open Recent isn't used at all at that moment.

So if you open your project via Open Recent Project, is your unit R/W at that moment, like it should be?
« Last Edit: November 14, 2015, 11:24:00 pm by rvk »

bkercso

  • Newbie
  • Posts: 2
Re: Compiler directive issue
« Reply #8 on: February 12, 2016, 11:15:32 am »
Hi,

I'm new in this topic. :)
Maybe you can help me: I have a problem with using FindNext (AfterFindFirst).
When I write:

repeat
...
until FindNext(Info)<>0;

I get the error message:
"Syntax error: "." expected but "(" found"

Here is a pictuare about that. It accepts only when I using FindNext.BooleanVariable, but this is not a function anymore!
http://i68.tinypic.com/k0n7sz.png

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Compiler directive issue
« Reply #9 on: February 12, 2016, 11:20:35 am »
I get the error message:
"Syntax error: "." expected but "(" found"
I'm not sure what this has to do with this topic. You could have opened a separate topic in the beginners sections.

But as for your problem. You have a program named FindNext. In that case the FindNext-FUNCTION doesn't work anymore because that's the name of your program.

If you name your program FindNextProgram your error-message goes away.
Code: Pascal  [Select][+][-]
  1. program FindNextProgram;
  2.  

You even called your program FindNext2.pas pas so you also do
Code: Pascal  [Select][+][-]
  1. program FindNext2;
  2.  
(as long as you don't call it FindNext)
« Last Edit: February 12, 2016, 11:22:57 am by rvk »

bkercso

  • Newbie
  • Posts: 2
Re: Compiler directive issue
« Reply #10 on: February 12, 2016, 12:21:17 pm »
Many many THX!
This working now!! :D

 

TinyPortal © 2005-2018