I have revised my function like this:
function IsVCRedist32BitNeeded(): boolean;
var
Major, Minor, Bld, Rbld: Cardinal;
VCRuntimeInstalled: boolean;
begin
VCRuntimeInstalled := false; { Assume that VC Runtime is not installed }
Result := true;
{ Version number is: Major.Minor.Bld.Rbld }
{ Minimum valid version is: 14.14.26429.03 }
if (RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Major', Major) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Minor', Minor) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Bld', Bld) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Rbld', Rbld)) then
begin
VCRuntimeInstalled := true;
end
else if (RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Major', Major) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Minor', Minor) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Bld', Bld) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Rbld', Rbld)) then
begin
VCRuntimeInstalled := true;
end;
if(VCRuntimeInstalled) then
begin
{ Is the installed version at least 14.14 ? }
Result := Major < 14 or
(Major = 14 and (Minor < 14 or
(Minor = 14 and (Bld < 26429 or
(Bld = 26429 and Rbld < 3)))));
{ 'true' means we need to run the installer }
if (Result) then
begin
Log('Visual Studio Redist x86 is not already installed');
Result := True;
end
else
Log(FmtMessage('Visual Studio Redist x86 Version : found v%1.%2.%3.%4', [Major, Minor, Bld, Rbld]));
end;
end;
end;
It will not compile. It complains about line 978 having a type mismatch:
Result := Major < 14 or
(Major = 14 and (Minor < 14 or
(Minor = 14 and (Bld < 26429 or
(Bld = 26429 and Rbld < 3)))));
What is wrong?
Pascal Script seems to have a non-standard operator precedence.
Additional brackets will solve this (and it's always better to use them anyway):
Result := (Major < 14) or
((Major = 14) and ((Minor < 14) or
((Minor = 14) and ((Bld < 26429) or
((Bld = 26429) and (Rbld < 3))))));