[英]How to allow to only install specific components in InnoSetup?
So the question is this: I asked a question back here: How to allow installation only to a specific folder? 所以问题是:我在这里问了一个问题: 如何只允许安装到特定的文件夹?
How can I modify it a bit, so for example, I have 3 files to install, 2 of them are optional and should only be available to install, if a certain file/folder exists. 如何修改它,例如,我有3个文件要安装,其中2个是可选的,如果存在某个文件/文件夹,应该只能安装。 I want to grey out the option to select them in the list, if the conditions are not met? 如果条件不满足,我想在列表中选择它们的灰色选项?
Thank you in advance. 先感谢您。 Zsolt 索尔特
I would try to do the following. 我会尝试做以下事情。 It will access the component list items, disable and uncheck them by their index, what is the number starting from 0 taken from the order of the [Components]
section. 它将访问组件列表项,通过索引禁用和取消选中它们,从[Components]
部分的顺序开始从0开始的数字是多少。 The items without fixed
flag (like in this case) are by default enabled, thus you need to check if the condition has not been met instead. 默认情况下启用没有fixed
标志的项目(如本例所示),因此您需要检查是否未满足条件。 You may check also the commented version
of this post: 您也可以查看这篇文章的commented version
:
[Components]
Name: Component1; Description: Component 1
Name: Component2; Description: Component 2
Name: Component3; Description: Component 3
[code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectComponents then
if not SomeCondition then
begin
WizardForm.ComponentsList.Checked[1] := False;
WizardForm.ComponentsList.ItemEnabled[1] := False;
WizardForm.ComponentsList.Checked[2] := False;
WizardForm.ComponentsList.ItemEnabled[2] := False;
end;
end;
The solution above has at least one weakness. 上述解决方案至少有一个缺点。 The indexes might be shuffled from the original order from the [Components]
section when you set the ComponentsList.Sorted
to True. 该指数可能从原来的顺序被打乱[Components]
节当您将ComponentsList.Sorted
为True。 If you don't 如果你不这样做
use it, it might be enough to use the above code, if yes, then it's more complicated. 使用它,它可能足以使用上面的代码,如果是的话,那就更复杂了。
There is no simple way to get the component name (it is stored internally as TSetupComponentEntry
object in the ItemObject
of each item), only the description, so here is another way to do the same with the difference that the item indexes are being searched by their descriptions specified. 没有简单的方法来获取组件名称(它在内部存储为每个项目的ItemObject
的TSetupComponentEntry
对象),只有描述,所以这里是另一种方法来做同样的事情,区别是项目索引被搜索他们的描述指定。
procedure CurPageChanged(CurPageID: Integer);
var
Index: Integer;
begin
if CurPageID = wpSelectComponents then
if not SomeCondition then
begin
Index := WizardForm.ComponentsList.Items.IndexOf('Component 2');
if Index <> -1 then
begin
WizardForm.ComponentsList.Checked[Index] := False;
WizardForm.ComponentsList.ItemEnabled[Index] := False;
end;
Index := WizardForm.ComponentsList.Items.IndexOf('Component 3');
if Index <> -1 then
begin
WizardForm.ComponentsList.Checked[Index] := False;
WizardForm.ComponentsList.ItemEnabled[Index] := False;
end;
end;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.