Avoid duplicates in list box (Inno Setup)

1

I receive an internet xml, which contains countries and currencies that may vary, then I charge it to a "List Box 1" and with the buttons on the screen I add or remove them from "List Box 2"

Here is an image of what I want: link

the code:

function LoadValuesFromXML(FileName: string): Boolean;
var
  XMLNode: Variant;
  XMLNodeList: Variant;
  XMLDocument: Variant;  
  Index: Integer;
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(FileName);
    if (XMLDocument.parseError.errorCode <> 0) then
    begin
      Log('The XML file could not be parsed. ' + XMLDocument.parseError.reason);
      Result := False;
    end
      else
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLNodeList := XMLDocument.SelectNodes('//listaPaises/item');
      for Index := 0 to XMLNodeList.length - 1 do
      begin
        XMLNode := XMLNodeList.item[Index];

        Log(
          Format('Pais = %s; Moneda = %s', [
          XMLNode.SelectSingleNode('name').Text,
          XMLNode.SelectSingleNode('suggestedCurrency').Text])); 

          comboBoxPais.items.Add(XMLNode.SelectSingleNode('name').Text); //Add Paises (countries) ???
          listBoxMonedasDisponibles.items.Add(XMLNode.SelectSingleNode('suggestedCurrency').Text);//Add Monedas (Currency)???
          listBoxMonedasDisponibles.ItemIndex := 0;
          comboBoxPais.ItemIndex := 0;
      end;
      Result := True;

    end;
  except
    Log('An error occured!' + #13#10 + GetExceptionMessage);
    Result := False;
  end;
end;
    
asked by Angel Montes de Oca 15.05.2017 в 19:10
source

1 answer

1
if listBoxMonedasDisponibles.Items.IndexOf(XMLNode.SelectSingleNode('suggestedCurrency').Text) < 0 then 
             listBoxMonedasDisponibles.Items.Add(XMLNode.SelectSingleNode('suggestedCurrency').Text);
             listBoxMonedasDisponibles.ItemIndex := 0;
    
answered by 16.05.2017 / 19:34
source