August 28th, 2012, 09:57 AM
Removing duplicates of a .txt file then send them to combobox
I have a .txt file having names.
I want to remove duplicates then send them to the combobox.
For example: A "names.txt" file has the following data:
it will be in format, duplicates removed:
then I will send them to the combobox.
how could I remove duplicates.
August 28th, 2012, 12:43 PM
It depends upon whether the items in your combobox must maintain their original order or whether they can be sorted.
If they can be sorted then all you need to do is something like this
NOTE: Code above not tested or checked in any way; but the process is correct.
tmpList := TStringList.Create;
tmpList.Sorted := True;
tmpList.Duplicates := duIgnore;
// Now add your items from file to tmpList
// Duplicates will be ignored
If you do NOT want the items sorted then you will either have to store the original order and re-arrange the items
or write your own algorithm for removing duplicates which, for efficiency, may depend
upon your knowledge of how duplicates may be separated in the file.
August 29th, 2012, 09:26 AM