本文介绍了Inno Setup函数未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望[InstallDelete]部分调用自定义函数,该函数将检查是否安装了旧版本(在这种情况下,在安装新版本之前,需要删除某些文件).

I would like the [InstallDelete] section to call a custom function that will check if an older version is installed (in which case certain files need to be deleted prior installation of the new version).

从我的Inno Setup脚本中提取.首先,如果安装了旧版本,则返回True的函数.

Extract from my Inno Setup script. First the function that returns True if an older version is installed.

[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
  MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', mbInformation, MB_OK);

  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', 'DisplayVersion') then
    begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', 'DisplayVersion', Version);
      MsgBox('Existing version:'+Version+'  New version:'+ExpandConstant('AppVersion'), mbInformation, MB_OK);
      if (Version < '1.013') then
        begin
          Result := True;
        end
      else
        begin
          Result := False;
        end
    end
  else
    begin
      Result := False;
    end
end;

然后是应调用此函数的部分:

Then the section that should call this function:

[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;

不幸的是,生成的安装程序似乎从未调用过自定义功能(使用此安装程序安装程序时,我从不获得位于自定义功能中的MsgBox,并且文件也不会被删除).

Unfortunately the generated setup seems to never call the custom function (when installing my program with this setup I never get the MsgBox located in the custom function and the files are not deleted).

我的函数是否有某些错误,这些错误在Inno Setup编译时未显示?如果是这样,我在哪里可以找到它们?

Is it possible that my function has some errors that are not indicated when Inno Setup compiles? If so, where could I find them?

任何帮助/提示将不胜感激;谢谢!

Any help / hint would be very much appreciated; thanks!

推荐答案

如果从不调用MsgBox,则还有其他问题.
我创建了一个新项目,按原样粘贴您的行,并弹出第一个msgbox.

If the MsgBox is never called, there is something else wrong.
I created a new project, pasted your lines as-is and the first msgbox pops-up.

也许只是开始一个新的,并继续从旧的安装脚本中添加部件,直到您发现阻止该功能执行的原因.

Maybe just start a new, and keep adding parts from your old setup script until you'll find what is stopping the function from executing.

您知道您可以使用F7和/或断点F5单步执行代码吗?那应该可以帮助您找到问题所在,应该去:[InstallDelete]-> [Dirs]-> [Files]

Did you know you can step through the code using F7 and/or breakpoints F5?That should help you locate the problem, It should go: [InstallDelete] -> [Dirs] -> [Files]

@IZB是正确的,ExpandConstant('AppId')将解析为AppId,而不是实际的ID.检查调试部分的输出,我在下面添加了脚本.逐步查看代码时,请观看Inno Seput编译器底部的调试输出".

@IZB is right, ExpandConstant('AppId') will be resolved as AppId and not the actual ID. Check the output from the debugging section I added the your script below. Watch the "Debug output" on bottom of Inno Seput Compiler while stepping through the code.

并且,您还需要ExpandConstant :),因为否则,您将把前导'{'翻倍.应当在[设置]部分中将其加倍以转义括号字符.预编译器也将使用#SetupSetting("AppId")通过转义前导括号. ExpandConstant实际上不会在此处扩展任何常量,但会删除此翻倍的子.

AND, You also need the ExpandConstant :) because otherwise you'll get the leading '{' doubled. It should be doubled in [Setup] section to escape the bracket character. The pre-compiler will pass the escape leading bracket too, using #SetupSetting("AppId") . ExpandConstant will not actually Expand any constant here, but will remove this doubled bractet.

这是完整的工作iss文件的粘贴:

Here is paste of complete working iss file:

#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

[Setup]
AppId={{CB77C990-DECF-4697-B377-8F76799CC6B7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin

  // Debugging
  // {#SetupSetting("AppId")} is short from {#emit SetupSetting("AppId")}
  Log('Note the double bracket: {#SetupSetting("AppId")}');
  Log('Now it''s fine: ' + ExpandConstant('{# SetupSetting("AppId")}'));
  Log(' This won''t expand: ' + ExpandConstant('AppId'));

  if RegValueExists(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion') then
    begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion', Version);
      MsgBox('Existing version:' + Version + '  New version:{#SetupSetting("AppVersion")}', mbInformation, MB_OK);
      if (Version < '1.013') then Result := True
      else Result := False;
    end
  else Result := False;
end;

[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check: deleteExistingHhd

这篇关于Inno Setup函数未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:24