Solved

How to use IFDEF?

Posted on 2011-09-16
18
356 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
18 Comments
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 167 total points
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 

Author Comment

by:Delphiwizard
Comment Utility
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 30

Expert Comment

by:Marco Gasi
Comment Utility
Place $define in your main form

Cheers
0
 

Author Comment

by:Delphiwizard
Comment Utility
No that doesn't work either.
0
 
LVL 30

Expert Comment

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

Author Comment

by:Delphiwizard
Comment Utility
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
Comment Utility
I can't as it is from a vender.
I need to ask them I guess.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
Comment Utility
The IFDEF in in a separate unit.
0
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 167 total points
Comment Utility
try in the project options

defines.JPG
0
 

Author Comment

by:Delphiwizard
Comment Utility
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 30

Expert Comment

by:Marco Gasi
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Marco Gasi
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you all for help with this question.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

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

13 Experts available now in Live!

Get 1:1 Help Now