Re: Detecting WIN32 or .NET example in a compiler directive



Skybuck Flying wrote:
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 ;))

Indeed. There's no reason to have two.

In your particular example, there's no reason for the compiler directives at all. Writeln and Readln work fine in .Net. They're defined as part of the Delphi language.

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

Yeah. So?

If you want to switch, close the project and re-open the DPR file. The IDE will ask which environment you want to use.

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

The problem is that it's really two different compilers. Compiler directives are processed by the compiler, obviously, but once you've invoked a compiler, it's too late to choose which one you want in a compiler directive.

--
Rob
.



Relevant Pages

  • Re: State of Forth 200x
    ... If you're referring to compiler directives, there are relatively few of them, certainly not "dozens". ... And although stack management is a new skill for folks who have had some prior exposure to programming, the concept of a compiler directive is familiar and straightforward. ... I don't see [CHAR] as a 'kludge'. ...
    (comp.lang.forth)
  • Re: Looking for explanation of comment block {}
    ... Meaning, ... > becomes a compiler directive. ... to add compiler directives, and the comment was probably chosen to make ... This made a lot of Pascal code compile with other Pascal compilers ...
    (borland.public.delphi.non-technical)
  • Re: Bug in Salfords FTN95 compiler version 5.20.1?
    ... When I snip source that I'm gonna fire up on my own compiler, ... all of the compiler options within a source file. ... When invoking the compiler from a command line in a Command Prompt ... in turn are superseded by any compiler directives given in the program. ...
    (comp.lang.fortran)
  • Re: Need versioning ?
    ... Use {$IFDEF XXX} statements. ... compiler directives in your project options. ...
    (borland.public.delphi.thirdpartytools.general)
  • 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)