Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6375419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:36:47+00:00 2026-05-25T01:36:47+00:00

Since I am writing a program that will eventually run on Windows and Linux

  • 0

Since I am writing a program that will eventually run on Windows and Linux environment compiled from the same project files, I wanted to test and see how well the Operating System directives are. So, I wrote a sample code. The code seems to run unexpectedly or it just my imagination.

Here is the code:

method MainForm.ControlBtn_Click(sender: System.Object; e: System.EventArgs);
begin
  {$IFDEF linux}
    MessageBox.Show('This is Linux. Horay!!!', 'mypro',MessageBoxButtons.yesno);
  {$ENDIF}

  {$IFDEF WIN32}
    MessageBox.Show('This is Win32. Horay!!!', 'mypro',MessageBoxButtons.yesno);
  {$ENDIF}

  {$IFDEF CLR}
    MessageBox.Show('This is .NET Framework. Horay!!!', 'mypro',MessageBoxButtons.yesno);
  {$ENDIF}
end;

Now, when I run this method on Windows it pops up a message box with ‘This is .NET Framework. Horay!!!’ I kind of expected that being that it was running on Windows. When I ran it on Linux under Mono, it popped up a message box with the same message, “This is .NET FrameWork. Horay!!!” I was expecting to see Linux message, which is “This is Linux. Horay!!!” If this code is working correctly, then how do you check to see which platform your program is running on in the event you do need to execute different methods only supported by Linux or Mac or windows.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:36:47+00:00Added an answer on May 25, 2026 at 1:36 am

    The compiler directives are evaluated at compile time (hence compiler directives). So the resulting .exe will always state the platform it was compiled on, not the one it is running on. Also, the Delphi-Compiler directives are not defined in this way for Prism / Oxygene language.

    The way to retrieve the OS you’re running on is a bit tricky (there are for example multiple values stating you’re on UNIX), but not overly complicated.

    The first place to go is System.Environment.OSVersion.Platform.
    This enum defines the following values in .NET 2.0: Win32S, Win32Windows, Win32NT, WinCE, Unix, Xbox, MacOSX. MacOS has its own value while Linux and other Unixoid systems share the Unix value.

    Mono also defines other values too (see the Mono FAQ entry on determining the platform).

    Edit: One possible way would be:

    var os: string := if Environment.OSVersion.Platform = System.PlatformID.Unix then
       'Linux/Unix'
    else if Environment.OSVersion.Platform = System.PlatformID.MacOSX then
       'Mac OS X'
    else
       'Windows';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a python3 program, that gets the names of files to process from
I'm writing a c# program that will launch many child processes. At some time
I'm writing a program for iPhone that will first let the user take a
I am writing a website with PHP. Since it will need to be accessed
I'm writing a program that for performance reasons uses shared memory (sockets and pipes
I am writing a program that needs to read a set of records that
I'm writing a program that sends an email out at a client's specific local
OK, so I am writing a program that unfortunately needs to use a huge
I am writing a numerical program that should be somewhat fast, and is also
Since I didn't do a good job writing the last question, and most of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.