Solved

How to use IFDEF?

Posted on 2011-09-16
18
369 Views
Last Modified: 2012-05-12
Hi,

In the source of some component some IFDEF is used.
I need to execute this code.

I've tried to add it:
- in the Directories/Conditionals of my project added: ADDIMG_CID;
- as {$define ADDIMG_CID} in the main unit
Both didn't work for me.

What do I need to do in order to activate this?
{$IFDEF ADDIMG_CID}
          if Copy(fnam, 1, 4) <> 'cid:' then
            fnam := 'cid:' + fnam;
{$ENDIF}

Open in new window

0
Comment
Question by:Delphiwizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 167 total points
ID: 36549720
You have to to add in your implementation section this

{$define ADDIMG_CID}



0
 
LVL 9

Assisted Solution

by:Lester_Clayton
Lester_Clayton earned 166 total points
ID: 36549731
If you trace from a few lines above this IFDEF - can you see if it's actually even getting to this block - and if it does get to it, does it just jump over it?

The code looks correct, so I'm wondering if it's even getting to the block in which this IFDEF is sitting.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36549746
Sorry I was too fast (and superficial) in answering... Are you sure the code within $IFDEF clause is correct? Try to place a showmessage, something like

{$IFDEF ADDIMG_CID}
  showmessage('is ADDIMG_CID');
{$ENDIF}

Ifthe message appears, then the problem is in another place...
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:Delphiwizard
ID: 36549925
I did do the following:
Added {$define ADDIMG_CID} to the implementation setting of the unit (no form)

Added the showmessage:
{$IFDEF ADDIMG_CID}
showmessage('ADDIMG_CID');
          if Copy(fnam, 1, 4) <> 'cid:' then
            fnam := 'cid:' + fnam;
{$ENDIF}

The message is not shown.
When I remove the IFDEF, then this code is correclty executed.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36549989
Place $define in your main form

Cheers
0
 

Author Comment

by:Delphiwizard
ID: 36550053
No that doesn't work either.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36550074
I can't imagin what is not working: your code is correct. Can you post the whole unit?
0
 

Author Comment

by:Delphiwizard
ID: 36550138
When I add this code into my onshow-event, it works there.

{$IFDEF ADDIMG_CID}
   showmessage('Test');
{$ENDIF}

But still not in the other unit.
0
 

Author Comment

by:Delphiwizard
ID: 36550143
I can't as it is from a vender.
I need to ask them I guess.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36550367
I'm not sure but I suspect you can only use that in the main form/unit. The unit in which you have to use these directives is only used by the main unit of your project or it is part of the project?
0
 

Author Comment

by:Delphiwizard
ID: 36550523
The IFDEF in in a separate unit.
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 167 total points
ID: 36550946
try in the project options

defines.JPG
0
 

Author Comment

by:Delphiwizard
ID: 36551310
As you can see in my initial question I already tried to set it in the project option.
Currently I've asked my question also at the vendor. I got no alternatives for now, except for comment out the IFDEF in the code itself. But that would meen maintenance whenever new releases are distributed.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36551836
What I meant was: the unit $ifdef is in is part of the project (have you added it to the project) or it is simply a unit placed in a registered path used by the main unit? What I'm thinking is that if that unit is not part of the project could not see the $define placed in the main unit...
0
 

Author Comment

by:Delphiwizard
ID: 36553050
Yes I made a copy of the original unit and added it to the project.
This was basically done because I need to comment out these IFDEF in order to get it to work.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36554415
Sorry for this stupid question, I don't want to offend you but... Are you sure yor project now uses the unit added to the project and not the external unit? Really, I don't see any reason for your code is not working, so I'm thinking about something little mistake not directly referred to your code (which is right).

Cheers
0
 

Author Comment

by:Delphiwizard
ID: 36555468
Yes, I'm sure it uses this unit. But even when I doesn't. If I don't comment-out the IFDEF, both units are exactly the same, so it wouldn't make any difference.
0
 

Author Closing Comment

by:Delphiwizard
ID: 36580987
Thank you all for help with this question.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month6 days, 6 hours left to enroll

626 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