开发者

InnoSetup & Pascal - Type mismatch error on run even after successful compile

开发者 https://www.devze.com 2022-12-19 10:19 出处:网络
When I compile the code below, it completes without errors, but when I attempt to run the setup file I get a type mismatch error. Can anyone tell me what might be causing it? (exact error message is \

When I compile the code below, it completes without errors, but when I attempt to run the setup file I get a type mismatch error. Can anyone tell me what might be causing it? (exact error message is "Runtime Error (at 1:66): Type Mismatch.")

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

[Code]
f开发者_运维知识库unction AppDir(Param: String): String;
var
 Check: Integer;
begin
 Check := GetWindowsVersion();
 if Check = 6.0 then
 Result := ExpandConstant('{userdocs}')
 else
 Result := ExpandConstant('{pf}');
end;


Quoting from the Inno Setup documentation for GetWindowsVersion():

Returns the version number of Windows packed into a single integer. The upper 8 bits specify the major version; the following 8 bits specify the minor version; the lower 16 bits specify the build number. For example, this function will return $05000893 on Windows 2000, which is version 5.0.2195.

You can't compare with a floating point value, you need to extract the parts of the version number, like so:

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;

Note that you should never check VerMajor for equality, as this would fail for either lower or higher Windows versions. Always use <= or >= instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消