选择特定组件后,Inno Setup会禁用组件选择 [英] Inno Setup disable component selection when a specific component is selected

查看:81
本文介绍了选择特定组件后,Inno Setup会禁用组件选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to be able to disable the selection of a component based on a specific component being selected. I cannot do this through nesting of components, as the component needs to be selectable on it's own, but not if another specific component is selected. Currently I handle this using the NextButtonClick event displaying a message:

if IsComponentSelected('Client') and IsComponentSelected('Sync') then
  begin
    MsgBox('A Client installation cannot have the Synchronisation component selected.',
      mbError, MB_OK);
      Result := False;      
  end;

防止用户继续操作,直到取消选择不兼容的组合为止.但是,如果我仅禁用组件的选择而不显示消息,那将更加优雅:

which prevents the user from continuing until they deselect the incompatible combination. However, it would be far more elegant if I could simply disable the selection of the component rather than displaying a message:

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;

问题是似乎没有事件允许用户在选择或取消选择组件时进行动态更改.有什么事件可以放置此代码或以其他方式执行此操作吗?

The problem is there doesn't seem to be an event that allows this to change dynamically as the user selects or deselects components. Is there an event I can place this code in or another way to do this?

推荐答案

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

The code I used in the end is based entirely on @TLama's code that he provided previously as this does not require the use of an external DLL.

[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的解决方案都可以使用,但是它们都显示图形化更新问题,即,当将组件的状态从活动状态更改为禁用状态时,反之亦然,在拖动滚动条之前,文本不会自动变暗或取消显示

Although this and @RobeN's solutions both work, they both exhibit a graphical update issue i.e. when changing the status of the components from active to disabled and vice versa, the text doesn't automatically dim or undim until the scroll bar is dragged.

请注意,上述刷新问题通过添加无效"来解决.线.上面更新的代码带有注释以反映这一点.有关更多信息,请参见 Inno Setup Components图形刷新问题.谢谢@TLama.

Note that the refresh issue described above is resolved by adding an `Invalidate;' line. Code updated above with a comment to reflect this. See Inno Setup Components graphical refresh issue for further information. Thanks @TLama.

这篇关于选择特定组件后,Inno Setup会禁用组件选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆