Examples Delphi

SEE AT END FOR THE PIECE OF PISS METHOD...
{first declare this procedure just after the word 'implementation'...}
{$IFDEF WIN32}
function GetVersionEx(lpOs : pointer) : BOOL; stdcall;
external 'kernel32' name 'GetVersionExA';
{$ENDIF}
procedure GetWindowsVersion(var Major: Integer; var Minor: Integer);
{the code here (to FIND THE WINDOWS VERSION) is fiddly but it works...}
var
{$IFDEF WIN32}
lpOS, lpOS2: POsVersionInfo;
{$ELSE}
l: longint;
{$ENDIF}
Win95OK: Boolean;
begin
Win95OK := False;
{$IFDEF WIN32}
GetMem(lpOS, SizeOf(TOsVersionInfo));
lpOs^.dwOSVersionInfoSize := SizeOf(TOsVersionInfo);
while getVersionEx(lpOS) = false do begin
GetMem(lpos2, lpos^.dwOSVersionInfoSize + 1);
lpOs2^.dwOSVersionInfoSize := lpOs^.dwOSVersionInfoSize + 1;
FreeMem(lpOs, lpOs^.dwOSVersionInfoSize);
lpOS := lpOs2;
end;
Major := lpOs^.dwMajorVersion;
Minor := lpOs^.dwMinorVersion;
{note that at this point we can also look at dwPlatformId like this:
if (lpOS^.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS) then
Win95OK := True
else Win95OK := False;}
FreeMem(lpOs, lpOs^.dwOSVersionInfoSize);
{$ELSE}
l := GetVersion;
Major := LoByte(LoWord(l));
Minor := HiByte(LoWord(l));
{$ENDIF}
end;
{FUNCTION THAT CALLS THE FUNCTION ABOVE...}
procedure TInstallForm.GoButtonClick(Sender: TObject);
var
Win95OK: Boolean;
Major : Integer;
Minor : Integer;
tempString: String;
begin
{Win95OK := GetWindows95;
if (Win95OK = False) then ShowMessage('Not Windows 98');}
GetWindowsVersion(Major, Minor);
tempString := 'Windows Major Version: ' + IntToStr(Major);
ShowMessage(tempString);
tempString := 'Windows Minor Version: ' + IntToStr(Minor);
ShowMessage(tempString);
end;
THE METHOD BELOW IS SUFFICIENT FOR CHECKING WHETHER
THE USER IS RUNNING WINDOWS 95 OR LATER...
function TInstallForm.GetWindows95: Boolean;
begin
{$IFDEF WIN32}
Result := True;
{$ELSE}
Result := False;
{$ENDIF}
end;