【问题标题】:Prevent duplicate items in list box and combo box in Inno Setup?防止 Inno Setup 中列表框和组合框中的重复项?
【发布时间】:2020-03-23 16:50:45
【问题描述】:

我从 Internet 收到一个 XML 文件(来自 XML 的值可能会有所不同,因为存在货币)。然后我将它加载到列表框 1。用户可以使用一些按钮(一一、全部、删除等)将项目添加到列表框 2。所以我想防止重复。我找不到任何方法来做到这一点。

我的列表框:

这是我的代码(XML解析部分,见How to read multiple XML nodes? (Inno Setup)):

XMLNodeList := XMLDocument.SelectNodes('//listaPaises/item');
for Index := 0 to XMLNodeList.length - 1 do
begin
  XMLNode := XMLNodeList.item[Index];

  { Add country }
  comboBoxPais.Items.Add(XMLNode.SelectSingleNode('name').Text); 

  { Add currency }
  listBoxMonedasDisponibles.Items.Add(XMLNode.SelectSingleNode('suggestedCurrency').Text);

  listBoxMonedasDisponibles.ItemIndex := 0;
  comboBoxPais.ItemIndex := 0;
end;

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    TComboBox.ItemsTListBox.Items 都是 TStrings 类型。

    使用TStrings.IndexOf,测试给定的字符串是否已经存在。如果字符串不存在,则返回负数 (-1)。

    { Add S only, if not present already }
    if comboBox.Items.IndexOf(S) < 0 then 
      comboBox.Items.Add(S);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多