【问题标题】:Inno Setup - Conditionally hide/show static text based on task selectionInno Setup - 根据任务选择有条件地隐藏/显示静态文本
【发布时间】:2016-03-05 19:13:51
【问题描述】:
[Components]
Name: "Slasher"; Description: "Dagon Slasher"; Types: Slasher Full
Name: "Frankenstein"; Description: "Dagon Frankenstein"; Types: Frankenstein Full

[Types]
Name: "Full"; Description: "Dagon Video Tools"
Name: "Slasher"; Description: "Dagon Slasher"
Name: "Frankenstein"; Description: "Dagon FrankenStein"

[Tasks]
Name: "Debug"; Description: "Nothing"; Components: not Slasher
Name: "Vid"; Description: "Install Extra Codecs for Frankenstein"; Flags: unchecked; Components: not Slasher

[Code]
var
  Warning: TNewStaticText;

procedure InitializeWizard;
begin
  Warning := TNewStaticText.Create(WizardForm);
  Warning.Parent := WizardForm.SelectTasksPage;
  Warning.Visible := False;
  Warning.AutoSize := False;
  Warning.SetBounds(
    WizardForm.TasksList.Left,
    WizardForm.TasksList.Top + WizardForm.TasksList.Height,
    WizardForm.TasksList.Width,
    50
  );
  Warning.Font.Color := clRed;
  Warning.Caption := 'Warning: This will result in a non-functional "Join in FrankenStein" button in the Tools Menu.';
end;

我使用了另一个惊人的code by TLama。问题是我需要在用户选择任务时显示注释,否则隐藏(在同一页面上)。

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    您必须处理WizardForm.TasksList.OnClickCheck 事件并相应地更新Warning 标签可见性。

    var
      Warning: TNewStaticText;
    
    procedure TasksListClickCheck(Sender: TObject);
    begin
      Warning.Visible :=
        { This (and the task index below)  has to be kept in sync with the expression }
        { in "Components" parameter of the respective task. }
        { Though note that in your specific case the test }
        { is redundant as when "Slasher" is selected, you have no tasks, }
        { and the "Tasks" page is completely skipped, so you do not even get here. }
        (not IsComponentSelected('Slasher')) and
        WizardForm.TasksList.Checked[0]; { You can also use WizardIsTaskSelected }
    end;
    
    procedure InitializeWizard;
    begin
      Warning := TNewStaticText.Create(WizardForm);
      ...
      { Update Warning label visibility on task selection change }
      WizardForm.TasksList.OnClickCheck := @TasksListClickCheck
    end;
    
    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurPageID = wpSelectTasks then
      begin
        { Update initial visibility }
        TasksListClickCheck(WizardForm.TasksList);
      end;
    end;
    


    旁注:

    • 不要将高度硬编码为固定的50。改为使用 DPI 缩放:ScaleY(50)
    • 您应该设置Warning.WordWrap := True,因为标题不适合页面宽度。
    • 您应该缩小TasksList 的高度,因为标签不适合列表下方。您缺少@TLama 代码中的WizardForm.TasksList.Height := WizardForm.TasksList.Height - NoteHeight;。再次注意他缺少NoteHeight 的缩放比例。
    const
      NoteHeight = 50;
    
    procedure InitializeWizard;
    begin
      WizardForm.TasksList.Height := WizardForm.TasksList.Height - ScaleY(NoteHeight);
    
      Warning := TNewStaticText.Create(WizardForm);
      Warning.Parent := WizardForm.SelectTasksPage;
      Warning.AutoSize := False;
      Warning.WordWrap := True;
      Warning.SetBounds(
        WizardForm.TasksList.Left,
        WizardForm.TasksList.Top + WizardForm.TasksList.Height,
        WizardForm.TasksList.Width,
        ScaleY(NoteHeight)
      );
      Warning.Font.Color := clRed;
      { Update Warning label visibility on task selection change }
      WizardForm.TasksList.OnClickCheck := @TasksListClickCheck
      Warning.Caption :=
        'Warning: This will result in a non-functional "Join in FrankenStein" button ' +
        'in the Tools Menu.';
    end;
    

    【讨论】:

    • 是的!非常感谢。在最后一次编辑之后,它可以工作(第一个,显然也影响了其他组件组合)!解决方案如此简单似乎很愚蠢,我对所有数字/组合和东西都感到困惑。我发誓,有一天我可以在脑海中完成这一切,将其写入脚本会容易得多。
    猜你喜欢
    • 2016-08-18
    • 2021-09-28
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 2017-01-31
    相关资源
    最近更新 更多