我希望能够禁用基于被选中的特定组件的组件的选择。我不能通过组件嵌套来做到这一点,因为组件需要自己选择,但如果选择了另一个特定组件,则不能这样做。目前,我使用显示消息的NextButtonClick
事件来处理这个问题:
if IsComponentSelected('Client') and IsComponentSelected('Sync') then
begin
MsgBox('A Client installation cannot have the Synchronisation component selected.',
mbError, MB_OK);
Result := False;
end;
这会阻止用户在取消选择不兼容的组合之前继续使用。但是,如果我可以简单地禁用组件的选择,而不是显示消息,那就更优雅了:
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;
问题是,在用户选择或取消组件时,似乎没有允许动态更改的事件。有什么事件我可以把这段代码放进去,或者用另一种方式来做到这一点?
发布于 2015-07-01 16:29:55
我最后使用的代码完全基于@TLama之前提供的代码,因为这不需要使用外部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的解决方案都能工作,但它们都存在一个图形更新问题,即当将组件的状态从活动更改为禁用时,文本在拖动滚动条之前不会自动变暗或不模糊。
请注意,上面描述的刷新问题是通过添加“issue;”行来解决的。上面用注释更新的代码以反映这一点。有关进一步信息,请参见Inno安装组件图形刷新问题。谢谢你。
https://stackoverflow.com/questions/31026473
复制相似问题