Detecting WIN32 or .NET example in a compiler directive



Hello,

I post this example because it might become handy in the future:

The question was how to detect WIN32 or .NET in a compiler directive.

***********************
* WIN32 example: *
***********************

*** Begin of Code ***:

program ProjectDetectWin32;

{$APPTYPE CONSOLE}

uses
SysUtils;

begin
{$IF DEFINED(WIN32)}
WriteLn('Welcome to the WIN32 world !');
Readln;
{$ELSEIF DEFINED(CLR)}
Console.WriteLine('Welcome to the .NET world !');
Console.ReadLine;
{$ELSE}
*** unknown world ;) ***
{$IFEND}
end.

*** End of Code ***

*********************
* .NET example: *
*********************

*** Begin of Code ***:

program ProjectDetectDotNet;

{$APPTYPE CONSOLE}

uses
SysUtils;

begin
{$IF DEFINED(WIN32)}
WriteLn('Welcome to the WIN32 world !');
Readln;
{$ELSEIF DEFINED(CLR)}
Console.WriteLine('Welcome to the .NET world !');
Console.ReadLine;
{$ELSE}
*** unknown world ;) ***
{$IFEND}
end.

*** End of Code ***

As you can see the code is exactly the same (except for the program
directive which does nothing ;))

However it seems it is necessary to create two different projects, one for
win32 and one for .net.

Maybe it's possible to create one project and simply use a compiler
directive to switch between compile environments ???

Bye,
Skybuck.


.



Relevant Pages

  • Re: Detecting WIN32 or .NET example in a compiler directive
    ... WriteLn('Welcome to the WIN32 world!'); ... there's no reason for the compiler directives ... Delphi for Win32 ...
    (alt.comp.lang.borland-delphi)
  • Re: The New Roadmap
    ... C# and Chrome don't have these issues because they don't have Win32 ... between different versions of the compiler and in both Win32 and .Net ... The question was "What's better in Delphi for .NET than C# or Chrome?", ... Forward migration of WinForms projects works ...
    (borland.public.delphi.non-technical)
  • Re: Can Someone Change My Mind About .NET?
    ... >> Win32 is not going away with LH. ... > the compiler that optimizes it for the current known processors. ... > If you do not recompile the .NET applcation and conventional program, ... > laid out in a certain memory order at the moment you compiled and linked. ...
    (microsoft.public.dotnet.general)
  • Re: Processing workload distribution
    ... underlying Win32 system calls still work the same way: ... There are no Win64 results from CPAN Testers, ... You need to use *exactly* the same compiler; ... Activestate provided with this build that Win32::process is available, ...
    (comp.lang.perl.misc)
  • Re: 64-bit on the horizon? (Was Re: Vista Requirement Already)
    ... Win64 code is very often slower than win32 because the size of the ... by 1.3 thought the i386 compiler contains more code because ... you be comparing cross-compilation results? ... So I still don't see how you conclude that memory footprint ...
    (borland.public.delphi.non-technical)