[fpc-pascal] Proper preprocessor?
Sven Barth
pascaldragon at googlemail.com
Fri Jun 22 23:47:16 CEST 2018
Am 22.06.2018 um 23:10 schrieb Marcos Douglas B. Santos:
> On Fri, Jun 22, 2018 at 5:13 PM, Florian Klämpfl <florian at freepascal.org> wrote:
>> {$macro on}
>>
>> {$define TypeStr:=specialize _TypeStr}
>>
>> begin
>> Writeln(TypeStr<TMyRecord>);
>> end.
> Can I use the same idea but for units?
>
> Like this:
>
> {$macro on}
>
> uses
> {$ifdef debug}
> foo_debug
> {$define foo := foo_debug}
> {else}
> foo_run;
> {$define foo := foo_run}
> {$enfif}
>
> begin
> foo.SomeFunc;
> end;
Why not simply test it?
That said you can also do this:
=== code begin ===
{$macro on}
{$ifdef debug}
{$define foo := foo_debug}
{$else}
{$define foo := foo_run}
{$endif}
uses
foo;
begin
foo.SomeFunc;
end.
=== code end ===
Though more often than not such things are done by simply using a
different set of units with the same names in a different unit path.
Regards,
Sven
More information about the fpc-pascal
mailing list