Link to home
Start Free TrialLog in
Avatar of Commsquare
Commsquare

asked on

Problem with conditional defines

In my conditional defines i have defined 'DELPHI'. In my code i have:
{IFNDEF DELPH}
{$mode objfpc}{$H+}
{$ENDIF}

but it cannot compile:
[DCC Error] MyUniit.pas(4): E1030 Invalid compiler directive: 'mode'
If i change IFNDEF to IFDEF, it compiles. This obviously means that it doesn't know DELPHI. I can compile exactly the same code on another machine with also Delphi 2007. How is this possible?
Avatar of 2266180
2266180
Flag of United States of America image

the correct way of doing this is

{IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}

:) I use this and it works just fine, because in fpc you don't need to define fpc, but in delphi, you need to define delphi. and in case you forget or use the unit in a project that doesn't have delphi defined... well, all sort of problems. so I suggest testing against fpc instead ;)
Well, I'm not sure, but it doesn't matter if it's IFNDEF DELPHI or IFDEF FPC, in the end it does the same even though IFNDEF DELPHI is kinda wrong...

Imo it'd be because of the missing $ sign:

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}

(If he used that exact code of course)
Avatar of Commsquare
Commsquare

ASKER

sorry, the code i have is indeed (with $):

{$IFNDEF DELPH}
{$mode objfpc}{$H+}
{$ENDIF}



it works on one pc, then why not on another pc? The code comes from a repository, same revision, ... It's really very strange.
>> Imo it'd be because of the missing $ sign:
lol. true. I only copy-pasted :D hence the error.

the diufference between ifndef delphi and ifdef pfc is, as I explained, that the fpc compiler sets FPC by default, whereas delphi does not set something standard, only version specific.
>>The code comes from a repository, same revision,

btw, never trust the repository as being 100% correct. it happened to many of us too many times when bad code was commited.

open project properties and see if the necessary defines are really set. but I am telling you, using the fpc define will definetly work.
People, trust me, the DELPHI define is set.
It's not working for any define, so the problem will hit me later anyway. It just seems to ignore these defines, is there maybe somewhere an IDE option that takes care of this?

:o I hope you're kidding.

if you do

{$DEFINE test}

{$IFDEF test}
bingo
{$ENDIF}

do you get a compilation error on bingo?
It's the conditional defines from Project-Options-Directories/Conditionals-Conditional Defines that are ignored, not the ones that you define in the code like you do.

you do realise I had to ask :) just sa I have to ask this:

we usually do this from reflex so that's why we don't usually ask: is this happening when you use "build all" as well? ("build all projects", etc, depending on your delphi version)

just humor me.

create a new project, add to the unit code:
{$IFDEF test}
bingo
{$ENDIF}

and compile. you should not receive any compiler errors.

open project properties and add "test" to the conditional defines. reBUILD project. you should get compiler errors.

is everything ok until now? if it is, then your compiler and IDE are fine. now we can concentrate on this being a project configuration problem.
open up the faulty project and add
{$IFDEF test}
bingo
{$ENDIF}
to the main unit.
build. you should not get any errors.
no add test to the conditional define list and reBUILD. you should get errors.

is this ok too?

if so, then go for your fault delphi compiler define. remove it from the list and REBUILD. you should get errors. add it back and reBUILD. you should not get errors.

is it ok now?

where did the test fail? and remember, unless you forgot to rebuild instead of recompile, do these tests in this exact order and report success/failure as appropriate.
1. also happening with build all: yes
2. new project, compiles: yes
3. add test to the conditional defines: STILL COMPILES!!!

so it seems to be an IDE problem...


you have 6 test cases tehre, you reported 3 results. needless to say this doesn't help me much. so please report me all 6 results for all 6 test scenarios so I can use valid data to draw a correct conclusion.

and since we're at it, can you handle command line compilation? have you ever done that? I am asking so that I know how much info I need to give you before telling you what to test.
i only report the first three because it is clear that the third failing test points to the IDE. You say it yourself: "is everything ok until now" after the third test. It is not. The other tests are only relevant if the first tests didn't fail.
I have already done your other tests, it's exactly the same problem as with this test application.
I haven't done command line compilation but if you can give the command i could execute it.
is it really that hard to be clear? you say
"2. new project, compiles: yes". what should I understand from this? that it compiles in first scenario only and not second, or compiles in both scenarios?
I don't like to draw conclusions with unclear data. it happened way to many times when the other user was saying something and in the end he did something wrong and he draw the wrong conclusion based on which he reported the result back to me. so I was working with bad information and could not figure out why things were not working as expected.
so, I want the test result and I will do the one doing the interpretation.

I will assume now that the first test, second scenario failed, implying an ide/compiler issue. if my assumtion is wrong, please do correct me by providing accurate responses to all 6 test cases.

if you haven't saved the test project, do it now. save it to another folder, away fro your current faulty project.
you now have for example c:\test\test.dpr and pas and dfm and etc.

now go to your installation directory and check for a dcc32.exe. if you don't have it you cannot do command line compilation. so this ends here.

if you do have it:

open up a cmd window and call:
dcc32.exe
if that fails, call
set path="path to delphi 2007 full with drive\bin";%path%
then call dcc32,exe again. if still fails and you do have it there and you did not forget the quotes around the path above and you set correct path then you didn't do one of these things so go over them again.
just to be clear, here is an example:
set path="c:\program files\borland\delphi 2007\bin";%path%

now change directory to you test folder (c:\test) then call
dcc32.exe test.dpr

does it compile or not? it should

then call
dcc32.exe test.dpr -Dtest

does it compile or not? it shouldn't

now, if in the second test it still compiles, zip the test directory (delete the exe) and post it here.
if it doesn't compile, so it's as expected, it means the issue is definetly with the IDE. what 3rd party experts/wizards/add-ons/etc do you have installed?
you can do something liek this:
- compare these 3rd party stuff on your pc and the other pc on which you sayd it compiles fine.
- see what you have and is not there and uninstall it
- see what you have and is there and has a different version. if it's older then on the good PC, thgen upgrade to the same version. if it's newer, then upgrade to the same version on the good PC and see if it still compiles as expected. if it doesn't, then you found the problem and you'll need to downgrade on both PCs
after this operation both PCs should be the same in regards to 3rd party stuff (oh, and also check any patches present). basically now you should have the same delphi version with same 3rd party stuff versions on both PCs and it should compile on both.
if it still doesn't, you missed something. best thing is to uninstall, clean up the registry and directories and start clean: install only delphi, and try to compile. if you need some 3rd party stuff for compilation then make sure to install the same verison as on the good  machine. this is critical because:
- in older versions there can be bugs that were fixed in the version which is on the good machine and which causes your problem
- in newer versions there can be bugs that were not present in the older version from the good machine

lot of stuff to do so don't husrry and report back correctly and completely. keep in mind that both of us have other language than english as primary so even though something clearly means one thing for you, it can mean something else to me and vice-versa. so try not to cut corners because something is logically or otheriwse clear; it might not be that clear for me ;)
dcc32.exe test.dpr -> this compiles
dcc32.exe test.dpr -Dtest -> this does not compile

the delphi ide is different
11.0.2902.10471 (bad one) versus 11.0.2627.5503 (good one)
all other components are the same (really :-)
I have no idea how i could get back to the version 11.0.2627.5503 .
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial