Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
Delphi

New “TOSVersion” type in Delphi XE2

Author: Tóth Erik

Delphi XE2 is probably the most significant release since Delphi 1.  The number of new features is amazing and probably the biggest, most important one is FireMonkey – a brand new business application development platform that let you use Delphi or C++ to write applications that natively run on Windows and Mac OS.

If you are writing an application that is designed to run on Windows and Mac it can be very useful to be able to programmatically check what operation system the application is running against.

Delphi XE2 adds new “TOSVersion” record type to “System.SysUtils” unit that can be used to retrieve information about platform, architecture and version numbers of the underlying OS.

The “TOSVerison” is a record type, so there is no need to instantiate it before accessing its members.

Note the “TArchitecture” and “TPlatform” enumerated types are nested within “TOSVersion” type. I like this approach, where it is obvious where these two enumerations logically belong.

Hey! Let’s give this new type a try!

1. Create a new “Delphi FireMonkey HD Application”

2. Press “Ctrl + .” to bring up “IDE Insight”. Start typing “TPanel” and add it to the form. Set its “Align” property to “alTop”, so it is aligned on top of the form.

3. Add “TMemo” to the form and align it to “alClient”.

4. Add a “TButton” to the panel, double-click it and enter the following code into the “OnClick” event handler:

5. As the last step add a new empty Delphi unit to the application, save it as “uOSVersionUtils” and replace its content with the following code that contains two utility functions to convert “TArchitecture” and “TPlatform” values to strings:

When I run this application on Windows, after clicking the button, it looks like this:

When I run it on Mac OS it looks like this:

Using the methods and properties of the new Delphi XE2 “TOSVersion” you can make decisions in your code depending on the version of the underlying operating system your FireMonkey application is running against. That’s powerful stuff!

Delphi and FireMonkey programming is real fun!

The source code of the “OSVersionApp” demo is available for download from Embarcadero Code Central: http://cc.embarcadero.com/item/28481


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES