在Inno Setup中安装前使用[Code]更改AppId

6
在设置中,我为用户提供了使用单选按钮安装32位或64位版本的选项。
然后,我想将AppId附加为_32_64
我知道可以使用脚本常量更改AppId,但是需要调用函数时,Setup正在启动。但是在此时,单选按钮尚不存在,因此我收到错误消息“无法调用proc”。
我查阅了Inno Setup帮助,并且我读到您可以在安装过程开始之前的任何时间更改AppId(如果我理解正确的话)。
那么,我该如何做到这一点呢?
我期待您的答案!
1个回答

12

某些指令值的{code:...}函数会被多次调用,而其中之一是AppId。更具体地说,它会在创建向导表单之前和安装开始之前各被调用一次。你所能做的就是检查你试图获取值的复选框是否存在。你可以简单地询问它是否为Assigned,如下所示:

[Setup]
AppId={code:GetAppID}
...

[Code]
var  
  Ver32RadioButton: TNewRadioButton;
  Ver64RadioButton: TNewRadioButton;

function GetAppID(const Value: string): string;
var
  AppID: string;
begin
  // check by using Assigned function, if the component you're trying to get a
  // value from exists; the Assigned will return False for the first time when
  // the GetAppID function will be called since even WizardForm not yet exists
  if Assigned(Ver32RadioButton) then
  begin
    AppID := 'FDFD4A34-4A4C-4795-9B0E-04E5AB0C374D';
    if Ver32RadioButton.Checked then
      Result := AppID + '_32'
    else
      Result := AppID + '_64';
  end;
end;

procedure InitializeWizard;
var
  VerPage: TWizardPage;
begin
  VerPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
  Ver32RadioButton := TNewRadioButton.Create(WizardForm);
  Ver32RadioButton.Parent := VerPage.Surface;
  Ver32RadioButton.Checked := True;
  Ver32RadioButton.Caption := 'Install 32-bit version';
  Ver64RadioButton := TNewRadioButton.Create(WizardForm);
  Ver64RadioButton.Parent := VerPage.Surface;
  Ver64RadioButton.Top := Ver32RadioButton.Top + Ver32RadioButton.Height + 4;
  Ver64RadioButton.Caption := 'Install 64-bit version';
end;

谢谢你,TLama!我真的不知道这一切,但是你通过分享你的知识再次让我感到愉快 :) - user1662035

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接