比较两个字符串inno设置

Cyp*_*ert 3 string compare inno-setup

我想用以下代码检查文件的MD5:

[Code]
var
  MD5Comp: string;

procedure ExitProcess(uExitCode:UINT);
  external 'ExitProcess@kernel32.dll stdcall';

procedure CurStepChanged(CurStep: TSetupStep);
begin
  MD5Comp := '32297BCBF4D802298349D06AF5E28059';

  if CurStep = ssInstall then
  begin

   if not MD5Comp=GetMD5OfFile(ExpandConstant('{app}\cg.npa')) then
   begin
     MsgBox('A patched version detected. Setup will now exit.', mbInformation, MB_OK);
     ExitProcess(1);
   end;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

但是在比较两个字符串时出现"类型不匹配"错误,所以我假设这不是你比较它们的方式.

编辑:我已经尝试 if not CompareText(MD5Comp,GetMD5OfFile(ExpandConstant('{app}\cg.npa')))=0但它永远不会执行if中的内容.

TLa*_*ama 7

这似乎是Pascal脚本编译器的一个例外.你期待像这样的表达式(假设S1并且S2string变量):

if not (S1 = S2) then
Run Code Online (Sandbox Code Playgroud)

但是编译器会这样对待它:

if (not S1) = S2 then
Run Code Online (Sandbox Code Playgroud)

好吧,我个人希望编译器错误而不是运行时错误.如果您明确将该比较括在括号中,至少您可以通过简单的方法解决此问题,例如:

if not (MD5Comp = GetMD5OfFile(ExpandConstant('{app}\cg.npa'))) then
Run Code Online (Sandbox Code Playgroud)

或者可选地写更多字面:

if MD5Comp <> GetMD5OfFile(ExpandConstant('{app}\cg.npa')) then
Run Code Online (Sandbox Code Playgroud)

请注意,在这种情况下,不需要括号,因为使用<>运算符它将成为单个布尔表达式.