[Tutor] defined()

Alan Gauld ukc802591034 at btconnect.com
Tue Apr 4 18:47:29 CEST 2006


>> Which language(s) do you know that has such a feature?
>
> I should came from Marco Cantu's Delphi 2005 book, that I have read just
> recently.
> But I am unable to find it again.

I'd be very surprised if it came from Delphi for two reasons:
a) I used Delphi a lot for several years and never came across it! :-)
b) Delphi (or Object Pascal) is strictly statically typed and wouldn't
    even compile with any undefined values in the code.

BUT...
I just checked and it *is* in Delphi - a new feature in Delphi 6.
BUT it's not a language feature rather it is a compiler directive like
the C #ifdef. (And starts with uppercase D BTW). His example:

//--------------------
const debugControl = 2

{$IF Defined(DEBUG) and DebugControl > 3}
     // do stuff here
{$IFEND}
//---------------------

There is also a Declared directive too. These are not primarily intended
for determining whether a variable is defined or declared but to determine
whether a particular language feature has been defined or constant declared
in the current version of Delphi (post version 6 of course!)

Now that's an entirely different question in terms of how we do that in 
Python!
Which I'll lreave as an excercise for the readers ;-)


-- 
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld






More information about the Tutor mailing list