合并来自不同来源的事件函数 (InitializeWizard) 实现

Merging event function (InitializeWizard) implementations from different sources

我现在正在组合我想要的脚本,但它有一个错误。

当我输入句点时,它会 运行 但缺少其他功能。

这是我的代码:

procedure InitializeWizard;
begin
  MessageBoxTimeout(WizardForm.Handle, 'MsgBox ' +
    Timeout 'Setup', MB_OK or MB_ICONINFORMATION, 0, 2000);
end;

var
  TuneLabel: TLabel;

begin
  ExtractTemporaryFile('tune.xm');
  if BASS_Init(-1, 44100, 0, 0, 0) then
  begin
    SoundCtrlButton := TNewButton.Create(WizardForm);
    Music := BASS_MusicLoad(False, 
      ExpandConstant('{tmp}\tune.xm'), 0, 0, 
      EncodingFlag or BASS_SAMPLE_LOOP, 0);
    BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 10000);
    BASS_ChannelPlay(Music, False);

    SoundCtrlButton := TNewButton.Create(WizardForm);
    SoundCtrlButton.Parent := WizardForm;
    SoundCtrlButton.Left := 10;
    SoundCtrlButton.TabStop := False;
    SoundCtrlButton.Top := WizardForm.ClientHeight - 
      SoundCtrlButton.Height - 9;
    SoundCtrlButton.Width := 40;
    SoundCtrlButton.Caption :=
      ExpandConstant('{cm:SoundCtrlButtonCaptionSoundOff}');
    SoundCtrlButton.OnClick := @SoundCtrlButtonClick;
    TuneLabel := TLabel.Create(WizardForm);
    TuneLabel.Parent := WizardForm;
    TuneLabel.Caption := 'Tune';
    TuneLabel.Left := SoundCtrlButton.Left + SoundCtrlButton.Width + ScaleX(5);
    TuneLabel.Top :=
      SoundCtrlButton.Top + ((SoundCtrlButton.Height - TuneLabel.Height) div 2);
  end;
end;

错误指的是最后end;之后的一行。

请帮我解决。

当您重复使用来自不同来源的各种功能实现时,它们通常实现相同的 Inno Setup event functions(如 InitializeWizard)。

Inno Setup 6的解决方法很简单,如下图。在旧版本中,它更复杂。见下方。


Inno 设置 6

Inno Setup 6 具有 event attributes 有助于解决此问题的功能。

只需确保您的每个事件实现都有一个唯一的名称,例如附加唯一后缀。并使用已实施事件的名称添加 event 属性。

[Code]
procedure InitializeWizard;
begin
  Log('InitializeWizard called');
end;

<event('InitializeWizard')>
procedure InitializeWizard2;
begin
  Log('InitializeWizard2 called');
end;

Inno 设置 5

在不支持事件属性的旧版本 Inno Setup 中,您必须合并这些事件函数,因为可能只有一个函数实现。

您可以通过将唯一后缀附加到不同的实现而不是从主实现中调用它们来做到这一点。

主要实现必须低于其他实现。

例如,如果一个源具有 InitializeWizard 事件函数实现为:

var
  GlobalVariable1: Integer;

procedure SubProcedure1;
begin
  { blah }
end;

procedure InitializeWizard;
var
  Variable1: Integer;
  Variable2: Integer;
begin
  Variable1 := GlobalVariable1;
  SubProcedure1;
end;

另一个来源为:

var
  GlobalVariableA: Integer;

procedure SubProcedureA;
begin
  { blah }
end;

procedure InitializeWizard;
var
  VariableA: Integer;
begin
  VariableA := GlobalVariableA;
  SubProcedureA;
end;

那么合并后的代码应该是:

var
  GlobalVariable1: Integer;

procedure SubProcedure1;
begin
  { blah }
end;

procedure InitializeWizard1;
var
  Variable1: Integer;
  Variable2: Integer;
begin
  Variable1 := GlobalVariable1;
  SubProcedure1;
end;

var
  GlobalVariableA: Integer;

procedure SubProcedureA;
begin
  { blah }
end;

procedure InitializeWizard2;
var
  VariableA: Integer;
begin
  VariableA := GlobalVariableA;
  SubProcedureA;
end;

procedure InitializeWizard;
begin
  InitializeWizard1;
  InitializeWizard2;
end;

另见


因此,在您的特定情况下,代码应为:

procedure InitializeWizard1;
begin
  MessageBoxTimeout(WizardForm.Handle, 'MsgBox ' +
    Timeout 'Setup', MB_OK or MB_ICONINFORMATION, 0, 2000);
end;

procedure InitializeWizard2;
var
  TuneLabel: TLabel;
begin
  ExtractTemporaryFile('tune.xm');
  if BASS_Init(-1, 44100, 0, 0, 0) then
  begin
    SoundCtrlButton := TNewButton.Create(WizardForm);
    Music := BASS_MusicLoad(False, 
      ExpandConstant('{tmp}\tune.xm'), 0, 0, 
      EncodingFlag or BASS_SAMPLE_LOOP, 0);
    BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 10000);
    BASS_ChannelPlay(Music, False);

    SoundCtrlButton := TNewButton.Create(WizardForm);
    SoundCtrlButton.Parent := WizardForm;
    SoundCtrlButton.Left := 10;
    SoundCtrlButton.TabStop := False;
    SoundCtrlButton.Top := WizardForm.ClientHeight - 
      SoundCtrlButton.Height - 9;
    SoundCtrlButton.Width := 40;
    SoundCtrlButton.Caption :=
      ExpandConstant('{cm:SoundCtrlButtonCaptionSoundOff}');
    SoundCtrlButton.OnClick := @SoundCtrlButtonClick;
    TuneLabel := TLabel.Create(WizardForm);
    TuneLabel.Parent := WizardForm;
    TuneLabel.Caption := 'Tune';
    TuneLabel.Left := SoundCtrlButton.Left + SoundCtrlButton.Width + ScaleX(5);
    TuneLabel.Top :=
      SoundCtrlButton.Top + ((SoundCtrlButton.Height - TuneLabel.Height) div 2);
  end;
end;

procedure InitializeWizard;
begin
  InitializeWizard1;
  InitializeWizard2;
end;

如果您使用的是 Inno Setup Script #Includes (ISSI),请参阅