如何从代码部分完全禁用Inno Setup中的特定组件?

阿兰

我有一个带有组件页面,复选框和组合框的Inno-setup脚本。我想取消选中并禁用“代码”部分中的某些组件,我使用了此答案来完成此工作,现在有了以下代码:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; 
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive

[code]
procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectComponents then
    if (True) then  //Here my own condition instead of "(True)"
    begin
      WizardForm.ComponentsList.Checked[1] := False;
      WizardForm.ComponentsList.ItemEnabled[1] := False;
    end;
end;

使用此选项,未选中代码中的“帮助”复选框,并且从代码中禁用了该复选框,但是即使用户无法单击“帮助”复选框也可以通过更改状态的组合框选择“完全安装” “帮助”复选框的状态从未选中变为选中(即使该复选框保持禁用状态)。

我想做的是完全禁用此组件并阻止用户选择它(不考虑用户尝试做的方式,单击它或在组合框中选择“完全安装”)。

TLama

这是另一种仍然很古怪的方式来做您想要的事情。我在这里使用了不同的概念。从本质上讲,它是关于准备应禁用和未选中的组件索引数组(我在此处称其为),并调用UpdateGhostItems(False)哪个未选中并禁用组件列表中已准备好的数组的索引项。

从安装类型更改组合框更改事件,仅通过调用UpdateGhostItems(True)以下命令检查此组合框可能更改的状态

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; 
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive

[Code]
var
  TypeChange: TNotifyEvent;
  GhostItems: array of Integer;

procedure UpdateGhostItems(CheckOnly: Boolean);
var
  I: Integer;
begin
  for I := 0 to GetArrayLength(GhostItems) - 1 do
  begin
    WizardForm.ComponentsList.Checked[GhostItems[I]] := False;
    if not CheckOnly then
      WizardForm.ComponentsList.ItemEnabled[GhostItems[I]] := False;
  end;
end;

procedure TypesComboChange(Sender: TObject);
begin
  // call the original event method
  TypeChange(Sender);
  // this will uncheck all the items from the GhostItems array;
  // this includes those that were checked by the above method
  // call; for GhostItems array description see below
  UpdateGhostItems(True);
end;

procedure InitializeWizard;
begin
  // store the original TypesCombo change event method
  TypeChange := WizardForm.TypesCombo.OnChange;
  // and assign it our interceptor
  WizardForm.TypesCombo.OnChange := @TypesComboChange;

  // the following code block is for setting ghosted components;
  // in real you might call it in some later stage of your setup

  // quite comfortable looks to me using array of indices of the
  // components that should remain always unchecked and disabled
  // I'm gonna prepare this array at the initialization but it's
  // really upon you when would you do so; so let's ghost 1 item
  SetArrayLength(GhostItems, 1);
  // ...with index 1
  GhostItems[0] := 1;
  // this call will uncheck and disable all the items from the
  // prepared GhostItems array; do note that this is a one way
  // road - once you disable a component, it won't get enabled
  // again (you would have to remember their previous state)
  UpdateGhostItems(False);
end;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Inno Setup:如何将变量从[代码]传递到[运行](或其他部分)

来自分类Dev

Inno Setup中较大的“选择组件”页面

来自分类Dev

如何使用Inno Setup作为必备组件安装.NET Framework?

来自分类Dev

如何根据Inno Setup中选择的组件设置启动程序?

来自分类Dev

Inno Setup:如何在“运行”部分或“运行”部分之前运行代码过程?

来自分类Dev

Inno Setup:选择组件的功能

来自分类Dev

如何在Inno Setup的“浏览文件夹”对话框中禁用“确定”按钮

来自分类Dev

Inno Setup-在“选定组件”菜单上禁用下拉列表

来自分类Dev

如何禁用特定代码部分的JSCS验证:行必须最多为120个字符

来自分类Dev

Inno Setup:如何在“运行”部分操作进度栏?

来自分类Dev

Inno Setup:如何在“注册”部分操作进度栏?

来自分类Dev

如何使用Inno Setup的[Code]部分中的值设置注册表项(环境变量)?

来自分类Dev

Inno Setup遍历Pascal代码中的[Files]部分

来自分类Dev

如果在Inno Setup中未选择任何组件,如何禁用“下一步”按钮?

来自分类Dev

Inno Setup:从菜单中禁用特定类型-类似于先前发布的Components方法

来自分类Dev

如何在Inno Setup Run部分中运行Set-ProcessMitigation PowerShell cmdlet

来自分类Dev

在Inno Setup中安装部分后,如何移动任务部分?

来自分类Dev

如何在Inno Setup的[CustomMessages]部分中使用通配符?

来自分类Dev

仅在Inno Setup中的特定页面中播放声音

来自分类Dev

如何不渲染reactjs中的组件特定部分

来自分类Dev

如何在Inno Setup中为OutputBaseFilename的版本组件填充零

来自分类Dev

如何检查Inno Setup中是否安装了特定的Python版本?

来自分类Dev

在Xamarin中禁用对屏幕上特定组件的触摸

来自分类Dev

Inno Setup-如何在设置过程中从文本文件编辑特定行?

来自分类Dev

如何使用代码中[Setup]部分中的值?

来自分类Dev

Inno Setup的只有特定的组件选择任务检查

来自分类Dev

选择特定组件后,Inno Setup会禁用组件选择

来自分类Dev

如何通过“参数”隐藏外部安装程序的欢迎页面并直接转到Inno Setup中的“组件”页面?

来自分类Dev

JSCS如何为代码规则的特定部分禁用requireDotNotation?

Related 相关文章

  1. 1

    Inno Setup:如何将变量从[代码]传递到[运行](或其他部分)

  2. 2

    Inno Setup中较大的“选择组件”页面

  3. 3

    如何使用Inno Setup作为必备组件安装.NET Framework?

  4. 4

    如何根据Inno Setup中选择的组件设置启动程序?

  5. 5

    Inno Setup:如何在“运行”部分或“运行”部分之前运行代码过程?

  6. 6

    Inno Setup:选择组件的功能

  7. 7

    如何在Inno Setup的“浏览文件夹”对话框中禁用“确定”按钮

  8. 8

    Inno Setup-在“选定组件”菜单上禁用下拉列表

  9. 9

    如何禁用特定代码部分的JSCS验证:行必须最多为120个字符

  10. 10

    Inno Setup:如何在“运行”部分操作进度栏?

  11. 11

    Inno Setup:如何在“注册”部分操作进度栏?

  12. 12

    如何使用Inno Setup的[Code]部分中的值设置注册表项(环境变量)?

  13. 13

    Inno Setup遍历Pascal代码中的[Files]部分

  14. 14

    如果在Inno Setup中未选择任何组件,如何禁用“下一步”按钮?

  15. 15

    Inno Setup:从菜单中禁用特定类型-类似于先前发布的Components方法

  16. 16

    如何在Inno Setup Run部分中运行Set-ProcessMitigation PowerShell cmdlet

  17. 17

    在Inno Setup中安装部分后,如何移动任务部分?

  18. 18

    如何在Inno Setup的[CustomMessages]部分中使用通配符?

  19. 19

    仅在Inno Setup中的特定页面中播放声音

  20. 20

    如何不渲染reactjs中的组件特定部分

  21. 21

    如何在Inno Setup中为OutputBaseFilename的版本组件填充零

  22. 22

    如何检查Inno Setup中是否安装了特定的Python版本?

  23. 23

    在Xamarin中禁用对屏幕上特定组件的触摸

  24. 24

    Inno Setup-如何在设置过程中从文本文件编辑特定行?

  25. 25

    如何使用代码中[Setup]部分中的值?

  26. 26

    Inno Setup的只有特定的组件选择任务检查

  27. 27

    选择特定组件后,Inno Setup会禁用组件选择

  28. 28

    如何通过“参数”隐藏外部安装程序的欢迎页面并直接转到Inno Setup中的“组件”页面?

  29. 29

    JSCS如何为代码规则的特定部分禁用requireDotNotation?

热门标签

归档