首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在选择特定组件时,Inno安装程序禁用组件选择

在选择特定组件时,Inno安装程序禁用组件选择
EN

Stack Overflow用户
提问于 2015-06-24 12:23:01
回答 2查看 2.7K关注 0票数 1

我希望能够禁用基于被选中的特定组件的组件的选择。我不能通过组件嵌套来做到这一点,因为组件需要自己选择,但如果选择了另一个特定组件,则不能这样做。目前,我使用显示消息的NextButtonClick事件来处理这个问题:

代码语言:javascript
运行
复制
if IsComponentSelected('Client') and IsComponentSelected('Sync') then
  begin
    MsgBox('A Client installation cannot have the Synchronisation component selected.',
      mbError, MB_OK);
      Result := False;      
  end;

这会阻止用户在取消选择不兼容的组合之前继续使用。但是,如果我可以简单地禁用组件的选择,而不是显示消息,那就更优雅了:

代码语言:javascript
运行
复制
if CurPageID = wpSelectComponents then
  begin
    if IsComponentSelected('Client') then
      begin
        WizardForm.ComponentsList.Checked[15] := False;
        WizardForm.ComponentsList.ItemEnabled[15] := False;
      end
    else
      begin
        WizardForm.ComponentsList.ItemEnabled[15] := True;
      end;
  end;

问题是,在用户选择或取消组件时,似乎没有允许动态更改的事件。有什么事件我可以把这段代码放进去,或者用另一种方式来做到这一点?

EN

Stack Overflow用户

回答已采纳

发布于 2015-07-01 16:29:55

我最后使用的代码完全基于@TLama之前提供的代码,因为这不需要使用外部DLL。

代码语言:javascript
运行
复制
[Code]
const
//Define global constants
  CompIndexSync = 15;
  CompIndexSyncClient = 16;
  CompIndexSyncServer = 17;

var
//Define global variables
  CompPageVisited: Boolean;
  DefaultCompClickCheck: TNotifyEvent;
  DefaultCompTypeChange: TNotifyEvent;

//Uncheck and set the enabled state of the Sync components based on whether the Client component is selected
procedure UpdateComponents;
begin
  with WizardForm.ComponentsList do
    begin
      if IsComponentSelected('Client') then
        begin
          CheckItem(CompIndexSync, coUncheck);
        end; 
      ItemEnabled[CompIndexSync] := not IsComponentSelected('Client');
      ItemEnabled[CompIndexSyncClient] := not IsComponentSelected('Client');
      ItemEnabled[CompIndexSyncServer] := not IsComponentSelected('Client');
      Invalidate; //required for text state to update correctly
    end;
end;

//Update the component states if the component states change and restore the original event handler procedures
procedure ComponentsClickCheck(Sender: TObject);
begin
  DefaultCompClickCheck(Sender);
  UpdateComponents;
end;

procedure ComponentsTypesComboChange(Sender: TObject);
begin
  DefaultCompTypeChange(Sender);
  UpdateComponents;
end;

procedure InitializeWizard();
begin
//Store the original Components Page OnClickCheck and Types Combo Box OnChange event procedures and assign custom procedures
  DefaultCompClickCheck := WizardForm.ComponentsList.OnClickCheck;
  WizardForm.ComponentsList.OnClickCheck := @ComponentsClickCheck;
  DefaultCompTypeChange := WizardForm.TypesCombo.OnChange;
  WizardForm.TypesCombo.OnChange := @ComponentsTypesComboChange;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
//Update the Components Page if entered for the first time
  if (CurPageID = wpSelectComponents) and not CompPageVisited then
    begin
      CompPageVisited := True;
      UpdateComponents;
    end;
end;

虽然这和@RobeN的解决方案都能工作,但它们都存在一个图形更新问题,即当将组件的状态从活动更改为禁用时,文本在拖动滚动条之前不会自动变暗或不模糊。

请注意,上面描述的刷新问题是通过添加“issue;”行来解决的。上面用注释更新的代码以反映这一点。有关进一步信息,请参见Inno安装组件图形刷新问题。谢谢你。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31026473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档