views:

349

answers:

1

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]
function AppDir(Param: String): String;
var
 Check: Integer;
begin
 Check := GetWindowsVersion();
 if Check = 6.0 then
 Result := ExpandConstant('{userdocs}')
 else
 Result := ExpandConstant('{pf}');
end;
+1  A: 

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.

mghie