Solved

Problem with conditional defines

Posted on 2008-10-15
16
1,632 Views
Last Modified: 2013-11-23
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?
0
Comment
Question by:Commsquare
  • 8
  • 7
16 Comments
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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 ;)
0
 
LVL 3

Expert Comment

by:Freddy1990
Comment Utility
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)
0
 

Author Comment

by:Commsquare
Comment Utility
sorry, the code i have is indeed (with $):

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



0
 

Author Comment

by:Commsquare
Comment Utility
it works on one pc, then why not on another pc? The code comes from a repository, same revision, ... It's really very strange.
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
>> 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.
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
>>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.
0
 

Author Comment

by:Commsquare
Comment Utility
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?

0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
:o I hope you're kidding.

if you do

{$DEFINE test}

{$IFDEF test}
bingo
{$ENDIF}

do you get a compilation error on bingo?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Commsquare
Comment Utility
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.

0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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.
0
 

Author Comment

by:Commsquare
Comment Utility
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...


0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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.
0
 

Author Comment

by:Commsquare
Comment Utility
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.
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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 ;)
0
 

Author Comment

by:Commsquare
Comment Utility
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 .
0
 
LVL 28

Accepted Solution

by:
ciuly earned 500 total points
Comment Utility
>> I have no idea how i could get back to the version 11.0.2627.5503 .
get the kit used to install 11.0.2627.5503 and don't patch anything. or if that is a patched version (meaing kit plus patches), only patch what was patched for 11.0.2627.5503

you can also log a bug with CG and maybe they already have or will issue a patch for this issue.
it's a pretty critical issue, so I suspect that a patch already exists.  it all depends how long ago 11.0.2902.10471 was released.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now