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

时间:2016-11-09 17:20:48

标签: inno-setup

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

Screenshot

当我放一段时间时,它会运行但缺少其他功能。

这是我的代码:

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;之后的一行。

请帮助我。

1 个答案:

答案 0 :(得分:1)

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

您必须合并这些事件函数,因为只能有一个函数实现。

Inno Setup 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 Setup 5

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

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

例如,如果一个源的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;

另见Inno Setup - Merging implementations of event functions that return boolean (like InitializeSetup)

因此,在您的具体情况下,代码应为:

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安装脚本#Includes(ISSI),请参阅Implementing event functions InitializeWizard while using ISSI (to add background image) in Inno Setup: Duplicate identifier 'INITIALIZEWIZARD'