Get operating system information in Delphi programming
In our daily programming, what is often determined by the operating system used by the user? Why do you want to do this because: In order to adapt the application to different operating systems, it can make it better! For example before running an application, it should first determine that the user is WIN95 / 98, or WIN NT. Although these two are commonly used operating systems, in some respects are completely different, running well on Win95 / 98 is not necessarily in Win NT, so different operating systems There should be different program code to accommodate different needs, but also make the program run better and more stable.
How can I know what the operating system used by the user? We can use the API function to solve, the methods are as follows:
First prepare, create a new project, put a label1 on PROM1 (air is empty) and a Button1 (CAPTION for the operating system information), other properties constant, then enter the following program code:
Unit getVer;
Interface
Uses
Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls
Type
TFORM1 = Class (TFORM)
Button1: tbutton;
Label1: TLABEL;
Procedure Button1Click (Sender: TOBJECT);
Private
{Private Declarations}
public
{Public declarations}
END;
VAR
FORM1: TFORM1;
IMPLEMENTATION
{$ R * .dfm}
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
GETVER: OSVersionInfo; // Declare the required variables, please refer to the API function description file.
RET: longbool;
Begin
GETVER.DWOSVERSIONFOSIZE: = 148;
RET: = getversionEx (getver); // Call the API function judgment start
If getver.dwplatformid = ver_platform_win32_windows then
Label1.caption: = 'The operating system you use is: Windows95 / 98';
If getver.dwplatformid = ver_platform_win32_nt kil
Label1.caption: = 'The operating system you are using is: Windows NT';
END;
End.
Please run now (press F9), how! whether succeed?
If you don't know, please contact the author: zch619@hotmail.com, or you can view the corresponding API function description, the author will no longer reopeize!
Note: The above program is commissioned in Windows 2000, Delphi5.0.