Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing duplicate from TStringList

I am parsing a dataset and assigning values to TStringList i want to avoid the duplicates. I use the following code but still duplicates are inserted.

  channelList := TStringList.Create;
  channelList.Duplicates := dupIgnore;
  try
    dataset.First;
    while not dataset.EOF do
    begin
        channelList.Add(dataset.FieldByName('CHANNEL_INT').AsString)  ;
        dataset.Next;
    end;

why does the duplicates added?

  • http://docwiki.embarcadero.com/Libraries/XE2/en/System.Classes.TStringList.Duplicates
like image 774
Jeeva Avatar asked Jul 16 '13 08:07

Jeeva


People also ask

How do you remove duplicates from list in react native?

To remove the duplicates from an array in React, pass the array to the Set constructor, e.g. [... new Set(arr)] . Each value in a Set has to be unique, so any duplicates get automatically removed.


1 Answers

You did read http://docwiki.embarcadero.com/Libraries/XE2/en/System.Classes.TStringList.Duplicates , didn't you ?

Then you missed the most repeated word there - "sorted"

channelList.Sorted := true

var F: TField;

channelList := TStringList.Create;
channelList.Sorted := True;
channelList.Duplicates := dupIgnore;

try
   dataset.First;
   F := dataset.FieldByName('CHANNEL_INT');
   while not dataset.EOF do
   begin
      channelList.Add(F.AsString);
      dataset.Next;
   end;
like image 113
Arioch 'The Avatar answered Sep 23 '22 19:09

Arioch 'The