防止在Inno Setup中的列表框和组合框中出现重复项? [英] Prevent duplicate items in list box and combo box in Inno Setup?

查看:33
本文介绍了防止在Inno Setup中的列表框和组合框中出现重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I receive an XML file from internet (values ​from XML ​may vary, cause there are currencies). And then I load it to a list box 1. A user can add items to to list box 2 with some buttons (one by one, all, delete etc). So I want to prevent duplicates. I can't find any way to do this.

我的列表框:

这是我的代码(有关XML解析的部分,请参见如何读取多个XML节点?(Inno设置)):

Here is my code (for XML parsing part, see 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;

推荐答案

TComboBox.Items TListBox.Items 均为 TStrings

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

Use TStrings.IndexOf, to test if a given string is already present. It returns a negative number (-1), if the string is not present.

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

这篇关于防止在Inno Setup中的列表框和组合框中出现重复项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆