Kamran
Kamran

Reputation: 387

Use macro codes in Delphi like C/C++

I found this macro code in Delphi/Pascal syntax but i can't use it! Does Delphi support macro codes like C/C++ or this macro is for another language such as Lazarus ???

The macro :

{$ifdef Profile}
  {$define __TRACE__:= try }
  {$define __END__:= finally ShowMessage('Hello !'); end;}
{$else}
  {$define __TRACE__:= //}
  {$define __END__:=}
{$endif}

I'm trying to use like this :

    ...
   __TRACE__
     // Somethings
    __END__
    ...

I caught this compiler message :

[dcc32 Error] Unit1.pas(37): E2003 Undeclared identifier: '__TRACE__'
[dcc32 Error] Unit1.pas(38): E2066 Missing operator or semicolon
[dcc32 Error] Unit1.pas(39): E2003 Undeclared identifier: '__END__'

{Excuse me if my English is bad}

Upvotes: 0

Views: 1209

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

These are Free Pascal macros. There's nothing at all like this available for the Delphi compiler. Some options:

  • Use a logging framework (there are many good logging libraries available) to add trace debug facilities to the code. Frankly that would be a huge improvement on what is shown here.
  • Expand the code manually. That is each time you see __TRACE__ in the code, replace that with an inline $IFDEF. Not appealing at all.

Upvotes: 2

Related Questions