比较两个字符串 inno setup
Compare two strings 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;
但是我在比较两个字符串时遇到 "Type Mismatch" 错误,所以我假设这不是您比较它们的方式。
编辑: 我试过 if not CompareText(MD5Comp,GetMD5OfFile(ExpandConstant('{app}\cg.npa')))=0
但它从不执行 if 中的内容。
这似乎是 Pascal Script 编译器的一个例外。您期待这样的表达式(假设 S1
和 S2
是 string
变量):
if not (S1 = S2) then
但是编译器是这样处理的:
if (not S1) = S2 then
好吧,我个人希望这里出现编译器错误而不是运行时错误。如果您将比较明确地括在括号中,至少您有简单的方法来解决此问题:
if not (MD5Comp = GetMD5OfFile(ExpandConstant('{app}\cg.npa'))) then
或者选择更直白地写:
if MD5Comp <> GetMD5OfFile(ExpandConstant('{app}\cg.npa')) then
请注意,在这种情况下不需要括号,因为使用 <>
运算符它变成了单个布尔表达式。
我想使用以下代码检查文件的 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;
但是我在比较两个字符串时遇到 "Type Mismatch" 错误,所以我假设这不是您比较它们的方式。
编辑: 我试过 if not CompareText(MD5Comp,GetMD5OfFile(ExpandConstant('{app}\cg.npa')))=0
但它从不执行 if 中的内容。
这似乎是 Pascal Script 编译器的一个例外。您期待这样的表达式(假设 S1
和 S2
是 string
变量):
if not (S1 = S2) then
但是编译器是这样处理的:
if (not S1) = S2 then
好吧,我个人希望这里出现编译器错误而不是运行时错误。如果您将比较明确地括在括号中,至少您有简单的方法来解决此问题:
if not (MD5Comp = GetMD5OfFile(ExpandConstant('{app}\cg.npa'))) then
或者选择更直白地写:
if MD5Comp <> GetMD5OfFile(ExpandConstant('{app}\cg.npa')) then
请注意,在这种情况下不需要括号,因为使用 <>
运算符它变成了单个布尔表达式。