【问题标题】:InnoSetup & Pascal - Type mismatch error on run even after successful compileInnoSetup & Pascal - 即使在成功编译后,运行时也会出现类型不匹配错误
【发布时间】:2010-02-05 00:57:07
【问题描述】:

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

【问题讨论】:

    标签: inno-setup pascal


    【解决方案1】:

    引用 GetWindowsVersion() 的 Inno Setup 文档:

    返回打包成单个整数的 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 版本都会失败。始终使用 <=>= 代替。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多