2
I have a file txt
with multiple records inside, I need something that at the time the function is added to the ListView
these records, do not let repeat items be added. To do this, it could use a certain column and compare. Inside the txt the delimiter I use is a @.
Code:
var
Linhas: TStringList;
Colunas: TStringList;
i,l: integer;
Item: TListItem;
begin
Linhas := TStringList.Create;
Colunas := TStringlist.Create;
Linhas.LoadFromFile('c:\clientes.txt');
for i := 0 to Linhas.Count-1 do
begin
Colunas.Text := StringReplace(Linhas[i],'@',Char(13)+Char(10),[rfReplaceAll]);
Item := Form1.LV.Items.Add;
l := l + 1;
Item.Caption := inttostr(l);
Item.SubItems.Add(Colunas[1]);
Item.SubItems.Add(Colunas[0]);
Item.SubItems.Add(Colunas[7]);
Item.SubItems.Add(Colunas[2]);
end;
end;
Try Subitems.Indexof(Columns[1]); if it returns < 0 it means it did not, if it returns >= 0 it means it has found
– Passella
@Passella, and if he finds repeats, how can I make him erase all leaving only 1 ?
– user7605
you have to do this check when insert the item
– Passella
See friend @Passella: if Item.SubItems.Indexof(Columns[2]) <= 0 then Begin Item.Caption := inttostr(l); Item.SubItems.Add(Columns[1]); Item.SubItems.Add(Columns[0]);
– user7605
It didn’t work, he’s adding repeated!
– user7605
show your entire code, not much to do without seeing it.
– Passella
@Passella, the code is the same and up, with the difference that I entered the rule that you passed before the Item.Caption, you understand ?
– user7605
@Passella, any suggestions ? our getting a little too caught up in this..
– user7605