delphiXE如何判断操作系统是win7还是winXP?delphi7的代码在XE上无效,没有那些函数,有哪位大大知道如何准确判断吗?不知道xe有没有这方面的函数

解决方案 »

  1.   

    D7上的可以话, 可以写在DLL, 然后调用通过返回值来判断.
      

  2.   

    XE比d7不是强一点半点,难道没有直接获取系统版本的函数?或更方便的方法?
      

  3.   

    以下代码 XE + XP下正确, WIN 7没有条件测试function GetWindowsVersionString: AnsiString;
    var
      ver: _OSVERSIONINFOA;
    begin
      if GetVersionExA(ver) then
        with ver do
          Result := Trim(
            Format(
            '%d.%d build %d %s',
            [dwMajorVersion, dwMinorVersion, dwBuildNumber, szCSDVersion]))
      else
        Result := '';
    end;function GetWindowsVersion: String; // 读取操作系统版本
    var
      AWin32Version: Extended;
      os: string;
    begin
      os := 'Windows ';
      AWin32Version := StrtoFloat(Format('%d.%d', [Win32MajorVersion, Win32MinorVersion]));
      if Win32Platform = VER_PLATFORM_WIN32S then
        Result := os + '32'
      else if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
      begin
        if AWin32Version = 4.0 then        Result := os + '95'
        else if AWin32Version = 4.1 then   Result := os + '98'
        else if AWin32Version = 4.9 then   Result := os + 'Me'
        else                               Result := os + '9x'
      end
      else if Win32Platform = VER_PLATFORM_WIN32_NT then
      begin
        if AWin32Version = 3.51 then        Result := os + 'NT 3.51'
        else if AWin32Version = 4.0 then    Result := os + 'NT 4.0'
        else if AWin32Version = 5.0 then    Result := os + '2000'
        else if AWin32Version = 5.1 then    Result := os + 'XP'
        else if AWin32Version = 5.2 then    Result := os + '2003'
        else if AWin32Version = 6.0 then    Result := os + 'Vista'
        else if AWin32Version = 6.1 then    Result := os + '7'
        else                                Result := os;
      end
      else                                  Result := os + '??';  Result := Result + ' ' + GetWindowsVersionString;
    end;
      

  4.   

    Msdn查一下GetVersionEx这个函数,
    看下Getting the System Version 这个例子
    我在偶的Vs2010的msdn里搜索到的
      

  5.   

    查 了编译指令  还没加入判断win7的。。
    相关的只有
    MSWINDOWS 
     Indicates that the operating environment is Windows. Use MSWINDOWS to test for any flavor of the Windows platform instead of WIN32. 
     
    WIN32 
     Indicates that the operating environment is the Win32 API. Use WIN32 for distinguishing between specific Windows platforms such as 32-bit versus 64-bit Windows. In general, do not limit code to WIN32 unless you know for sure that the code will not work in WIN64. Use MSWINDOWS instead. 
     
    CPU386 
     Indicates that the CPU is an Intel 386 or later.