Conditional compilation & Pre-processing 
Author Message
 Conditional compilation & Pre-processing

hi guys, im porting a college project from linux to windows, i developed
the project using the freePascal compiler and im trying to get it to
work using borland's tp for windows 1.5...

ive got two questions,

first, freepascal supports constructs like this:

{$IFDEF WINDOWS OR DEBUG}
....
{$ENDIF}

but i cant work out how to get boolean operators in these with borland,
ive tried this

{$IFDEF WINDOWS || DEBUG}

but thats not it..anyone know if its possible?

also, in the borland help pages it describes '#define' which sounds
like it works like the c pre-processor does, replacing all occurrences
of X with Y, i really hope it does, it would save me a lot of work! :)

but i cant get it to work, ive tried #define X Y, {#define X Y},
{$#define X Y}, i must be missing something! if anyone knows the secret
id love to hear it :)

btw, ive checked freepascals superior documentation but they dont even
mention #define so im guessing its a borland only thing...

Thanks for any help :)

--
-------------------------------------

-------------------------------------------------------



Mon, 30 May 2005 02:00:51 GMT  
 Conditional compilation & Pre-processing


Quote:
>hi guys, im porting a college project from linux to windows, i developed
>the project using the freepascal compiler and im trying to get it to
>work using borland's tp for windows 1.5...

>ive got two questions,

>first, freepascal supports constructs like this:

>{$IFDEF WINDOWS OR DEBUG}
>....
>{$ENDIF}

>but i cant work out how to get boolean operators in these with borland,
>ive tried this

>{$IFDEF WINDOWS || DEBUG}

Don't believe that is available in Borland's Pascal.

You can nest (embed) IFDEFs to do the same thing

Example snippet follows:

begin
 {$IFDEF Debug}
     Cnt := Cnt + 1;
     Buf := IntToHex(Cnt, 4) + ' ' + #0;

 {$IFDEF WIN32}
     OutputDebugString(PChar(Msg));
 {$ELSE}
     if Length(Msg) < High(Msg) then
         Msg[Length(Msg) + 1] := #0;


 {$ENDIF}
 {$ENDIF}
 end;

Quote:

>but thats not it..anyone know if its possible?

>also, in the borland help pages it describes '#define' which sounds
>like it works like the c pre-processor does, replacing all occurrences
>of X with Y, i really hope it does, it would save me a lot of work! :)

>but i cant get it to work, ive tried #define X Y, {#define X Y},
>{$#define X Y}, i must be missing something! if anyone knows the secret
>id love to hear it :)

>btw, ive checked freepascals superior documentation

Wow, awful bad language being used here.

Bet you've never walked into a "Hell's Angels" bar
and told them that the "Snakes" were superior. <g>

- Show quoted text -

Quote:
>but they dont even mention #define so im guessing its a borland only thing...

>Thanks for any help :)



Mon, 30 May 2005 03:37:25 GMT  
 Conditional compilation & Pre-processing

Quote:



>>hi guys, im porting a college project from linux to windows, i developed
>>the project using the freepascal compiler and im trying to get it to
>>work using borland's tp for windows 1.5...

>>ive got two questions,

>>first, freepascal supports constructs like this:

>>{$IFDEF WINDOWS OR DEBUG}
>>....
>>{$ENDIF}

Another example of embedding

Const
  {$IFDEF Ver70} Offset = 9;
  {$ELSE} {$IFDEF Ver60} Offset = 9;
  {$ELSE} {$IFDEF Ver55} Offset = 9;
  {$ELSE} {$IFDEF Ver50} Offset = 9;
  {$ELSE} {$IFDEF Ver40} Offset = 16;
  {$ELSE} CRASH HERE -- Only With TP4 And more
  {$ENDIF} {$ENDIF} {$ENDIF} {$ENDIF} {$ENDIF}

- Show quoted text -

Quote:
>>but i cant work out how to get boolean operators in these with borland,
>>ive tried this

>>{$IFDEF WINDOWS || DEBUG}

>Don't believe that is available in Borland's Pascal.

>You can nest (embed) IFDEFs to do the same thing

>Example snippet follows:

>begin
> {$IFDEF Debug}
>     Cnt := Cnt + 1;
>     Buf := IntToHex(Cnt, 4) + ' ' + #0;

> {$IFDEF WIN32}
>     OutputDebugString(PChar(Msg));
> {$ELSE}
>     if Length(Msg) < High(Msg) then
>         Msg[Length(Msg) + 1] := #0;


> {$ENDIF}
> {$ENDIF}
> end;

>>but thats not it..anyone know if its possible?

>>also, in the borland help pages it describes '#define' which sounds
>>like it works like the c pre-processor does, replacing all occurrences
>>of X with Y, i really hope it does, it would save me a lot of work! :)

>>but i cant get it to work, ive tried #define X Y, {#define X Y},
>>{$#define X Y}, i must be missing something! if anyone knows the secret
>>id love to hear it :)

>>btw, ive checked freepascals superior documentation

>Wow, awful bad language being used here.

>Bet you've never walked into a "Hell's Angels" bar
>and told them that the "Snakes" were superior. <g>

>>but they dont even mention #define so im guessing its a borland only thing...

>>Thanks for any help :)



Mon, 30 May 2005 03:40:40 GMT  
 Conditional compilation & Pre-processing


Quote:
>hi guys, im porting a college project from linux to windows, i developed
>the project using the freepascal compiler and im trying to get it to
>work using borland's tp for windows 1.5...

>ive got two questions,

>first, freepascal supports constructs like this:

>{$IFDEF WINDOWS OR DEBUG}
>....
>{$ENDIF}

>but i cant work out how to get boolean operators in these with borland,
>ive tried this

>{$IFDEF WINDOWS || DEBUG}

>but thats not it..anyone know if its possible?

>also, in the borland help pages it describes '#define' which sounds
>like it works like the c pre-processor does, replacing all occurrences
>of X with Y, i really hope it does, it would save me a lot of work! :)

>but i cant get it to work, ive tried #define X Y, {#define X Y},
>{$#define X Y}, i must be missing something! if anyone knows the secret
>id love to hear it :)

Forgot to answer this part in my previous messages.

Look at how "Debug" is defined and used in the example below:

{$A+,B+,D+,E-,F-,I+,L+,N-,O-,R+,S+,V+}
{$M 16384,0,655360}
{$DEFINE Debug}
PROGRAM debug;
VAR
  W : Word;
  L : LongInt;
{$IFDEF Debug}
  OldL : LongInt;

  PROCEDURE Nop; INLINE($90);
{$ENDIF}

- Show quoted text -

Quote:

>btw, ive checked freepascals superior documentation but they dont even
>mention #define so im guessing its a borland only thing...

>Thanks for any help :)



Mon, 30 May 2005 03:44:55 GMT  
 Conditional compilation & Pre-processing

[can't comment on the first, haven't used TP/BP that intensively lately]

Quote:
> but i cant get it to work, ive tried #define X Y, {#define X Y},
> {$#define X Y}, i must be missing something! if anyone knows the secret
> id love to hear it :)

Are you sure that it is not simply {$define xxx} ? (define something
to be tested with ifdef etc). Any way, I quickckecked my BP docs, and can't
find it.

Quote:
> btw, ive checked freepascals superior documentation but they dont even
> mention #define so im guessing its a borland only thing...

Btw: FPC has a limited macro facility, using $MACRO (see programmers guide),
though you need a parameter or preprocessor command to turn it on.


Mon, 30 May 2005 03:48:16 GMT  
 Conditional compilation & Pre-processing

Quote:




>>Don't believe that is available in Borland's Pascal.

>>You can nest (embed) IFDEFs to do the same thing

ok, i'll do that, thanks :)

--
-------------------------------------

-------------------------------------------------------



Mon, 30 May 2005 04:51:29 GMT  
 Conditional compilation & Pre-processing

Quote:

> hi guys, im porting a college project from linux to windows, i developed
> the project using the freepascal compiler and im trying to get it to
> work using borland's tp for windows 1.5...

> ive got two questions,

> first, freepascal supports constructs like this:

> {$IFDEF WINDOWS OR DEBUG}
> .....
> {$ENDIF}

> but i cant work out how to get boolean operators in these with borland,
> ive tried this

> {$IFDEF WINDOWS || DEBUG}

> but thats not it..anyone know if its possible?

It is not possible. You have to use a workaround:

    {$IFDEF WINDOWS}
    {$DEFINE WINDOWS_OR_DEBUG}
    {$ENDIF}

    {$IFDEF DEBUG}
    {$DEFINE WINDOWS_OR_DEBUG}
    {$ENDIF}

    {$IFDEF WINDOWS_OR_DEBUG}
    .....
    {$ENDIF}

Quote:
> also, in the borland help pages it describes '#define' which sounds
> like it works like the c pre-processor does, replacing all occurrences
> of X with Y, i really hope it does, it would save me a lot of work! :)

It doesn't and it won't:(

The Borland (pascal) variant is called '$DEFINE', but it definitely does
*not* work like '#define'. The only thing you can do with it is to define
a "symbol" (like DEBUG, WINDOWS or VER140) and then test if it exists/is
defined.

Regards, Ren



Mon, 30 May 2005 08:21:18 GMT  
 Conditional compilation & Pre-processing



Quote:

> [can't comment on the first, haven't used TP/BP that intensively
lately]

> > but i cant get it to work, ive tried #define X Y, {#define X Y},
> > {$#define X Y}, i must be missing something! if anyone knows the
secret
> > id love to hear it :)

> Are you sure that it is not simply {$define xxx} ? (define something
> to be tested with ifdef etc). Any way, I quickckecked my BP docs, and
can't
> find it.

Well it's there in the online help, but you have to know that you have
to look for $define
The help items about $ifdef, $ifndef, $elseif,  $endif are crosslinked
to each other, but not to $define. Also there are no examples in the
online help.

--
Femme



Mon, 30 May 2005 08:49:31 GMT  
 Conditional compilation & Pre-processing

Quote:


>> but thats not it..anyone know if its possible?

> It is not possible. You have to use a workaround:

>     {$IFDEF WINDOWS}
>     {$DEFINE WINDOWS_OR_DEBUG}
>     {$ENDIF}

>     {$IFDEF DEBUG}
>     {$DEFINE WINDOWS_OR_DEBUG}
>     {$ENDIF}

>     {$IFDEF WINDOWS_OR_DEBUG}
>     .....
>     {$ENDIF}

Thanks Ren! i hadnt thought of that, great idea :)

--
-------------------------------------

-------------------------------------------------------



Mon, 30 May 2005 19:43:29 GMT  
 Conditional compilation & Pre-processing

Quote:

>> Are you sure that it is not simply {$define xxx} ? (define something
>> to be tested with ifdef etc). Any way, I quickckecked my BP docs, and
> can't
>> find it.

> Well it's there in the online help, but you have to know that you have
> to look for $define
> The help items about $ifdef, $ifndef, $elseif,  $endif are crosslinked
> to each other, but not to $define. Also there are no examples in the
> online help.

I know {$define x} of course, but the original {#define <something>} is
something entirely different in functionality.

(besides the $define functionality, it also implements a macro facility)



Mon, 30 May 2005 22:50:21 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Batch processes & printing

2. addindex and conditional indexes

3. Conditional Images in DBGrid

4. Promblems with Apollo 2.0 and conditional indexes (Foxpro 2.6 .DBF)

5. Conditional Indexes

6. removing the source within conditionals

7. Conditional statement Problem Win 1.5

8. Conditional Break Point

9. Conditional Define problem in IDE

10. FIB Compilation error

11. Compilation trouble

12. Compilation Error HELP!!

 

 
Powered by phpBB® Forum Software