0

当我编译下面的代码时,它没有错误地完成,但是当我尝试运行安装文件时,我得到一个类型不匹配的错误。谁能告诉我可能是什么原因造成的?(确切的错误消息是“运行时错误(在 1:66):类型不匹配。”)

[Setup]
DefaultDirName={code:AppDir}\MyApp

[Code]
function AppDir(Param: String): String;
var
 Check: Integer;
begin
 Check := GetWindowsVersion();
 if Check = 6.0 then
 Result := ExpandConstant('{userdocs}')
 else
 Result := ExpandConstant('{pf}');
end;
4

1 回答 1

2

引用 Inno Setup 文档GetWindowsVersion()

返回打包成单个整数的 Windows 版本号。高 8 位指定主版本;以下 8 位指定次要版本;低 16 位指定内部版本号。例如,此函数将在 Windows 2000(版本 5.0.2195)上返回 $05000893。

无法与浮点值进行比较,需要提取版本号的部分,如下所示:

function AppDir(Param: String): String;
var
  Ver: Cardinal;
  VerMajor, VerMinor, BuildNum: Cardinal;
begin
  Ver := GetWindowsVersion();
  VerMajor := Ver shr 24;
  VerMinor := (Ver shr 16) and $FF;
  BuildNum := Ver and $FFFF;

  if VerMajor >= 6 then
    Result := ExpandConstant('{userdocs}')
  else
    Result := ExpandConstant('{pf}');
end;

请注意,您永远不应该检查VerMajor相等性,因为这对于较低或较高的 Windows 版本都会失败。始终使用<=or>=代替。

于 2010-02-05T07:50:45.397 回答