Inno Setup - 查看有多少组件被选中

Inno Setup - See how many components are selected

其实我只要看看是不是1以上就可以了。以下是我打算如何使用它:

if [Only one component is selected] then
begin
  Result := CustomMessage('[Name of that component]');
  if IsComponentSelected('[Specific Component]') then
  begin
    if IsTaskSelected('[Task]') then
    begin
      Result := CustomMessage('[Name of that task]');
    end
  end
end
if [More than one component is selected] then
begin
  Result := 'Full Feature';// or '{#SetupSetting("AppName")}'
end;

我想我至少知道一种 "workaround" 方法来做到这一点,但我想知道是否可以使用更传统的 Inno 方法(和更简洁的代码)来完成。

-----编辑-----

使用 Martins 答案的最终函数:

function UninstallName(Value: string): string;
begin
  if GetSelectedComponentsCount = 1 then
  begin
    Result := CustomMessage(WizardSelectedComponents(False));
    if IsComponentSelected('bc2') then
    begin      
      if IsTaskSelected('bc2tp2') then
      begin
        Result := CustomMessage('bc2tp2');
      end;
    end;
    if Pos(':',Result) > 1 then
    StringChangeEx(Result, ':', ' -', False)
  end;
  if GetSelectedComponentsCount > 1 then
  begin
    Result := '{#SetupSetting("AppName")}';
  end;
end;

检查 WizardForm.ComponentsList:

function GetSelectedComponentsCount: Integer;
var
  I: Integer;
begin
  Result := 0;
  for I := 0 to WizardForm.ComponentsList.Items.Count - 1 do
  begin
    if WizardForm.ComponentsList.Checked[I] then
      Result := Result + 1;
  end;
end;

您还可以计算 WizardSelectedComponents 中的元素数量:

function GetSelectedComponentsCount: Integer;
var
  S: TStringList;
begin
  S := TStringList.Create();
  S.CommaText := WizardSelectedComponents(False);
  Result := S.Count;
  S.Free;
end;

(计算逗号会更有效,代码会稍微少一些,但理解起来很神秘。)