在 Inno Setup 中防止列表框和组合框中的重复项?

Prevent duplicate items in list box and combo box in Inno Setup?

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

我的列表框:

这是我的代码(XML 解析部分,参见 ):

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;

TComboBox.ItemsTListBox.Items 都是 TStrings 类型。

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

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