need help with $DEFINE directive ... 
Author Message
 need help with $DEFINE directive ...

PC>What is a $DEFINE directive? The book talk about controlling Writeln
PC>using $IFDEF and $ENDIF complier directive.  Can you give example.

PC>Philip Chong


A simple example.... Say I wanted my program source code to compile in
one of two different versions, with one version being a debugging
version and the other being the final release. In the debugging version
I want to implement certain satements to help me debug it when I run it.
Here's how I might do it using $DEFINE's...

PROGRAM TheProg;

{$DEFINE DEBUG}

uses Crt;

var
   I: byte;

BEGIN
   for I := 1 to 255 do begin
      ... do some stuff here ...
{$IFDEF DEBUG}
      if I = 255 then WriteLn('Exiting FOR/DO loop...');
{$ENDIF}
   end;
   ...do more stuff here...
END.

Now, as long as I have DEBUG defined at the top of the program, the code
between the $IFDEF - $ENDIF will compile and execute for me. To not have
it execute I would just put a space before the $DEFINE like so...

{ $DEFINE DEBUG}

and that would turn it off, allowing me to compile and execute the
non-debugging program.

Get the idea?

        -- Kim Forwood --

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\

  %         For what purpose is life, if one cannot live freely?         $
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. need help with $DEFINE directive ...

2. Need help defining auto-incrementing field using TTable.Create

3. need help porting, how are these defined?

4. HELP : Define a dBase table using CreateTable

5. HELP user defined data types

6. HELP: how to use delphi to write interbase User Defined Functions

7. Include File Compiler Directive in Pascal

8. Delphi 4.0 Compiler {$IFDEF} directive problem

9. Compiler Directive for Protect Mode compilation?

10. Running DOS prompt and setting $M directive

11. Memory Allocation Sizes Directive and exec

12. Exec 'ing another prog {M} directive

 

 
Powered by phpBB® Forum Software