Board index » cppbuilder » ->Duplicates property...

->Duplicates property...


2006-05-03 07:05:52 PM
cppbuilder32
I am trying to remove duplicates from a ComboBox. I see that TStringList
has a duplicates property but I can't seem to be able to use it right?
Here is my code, editor->text contains 4 soundfiles with .wav
extensions, two are the same.
TStringList* soundfiles;
TStringList* nodups;
nodups= new TStringList;
soundfiles = new TStringList;
soundfiles->Delimiter = ',';
soundfiles->DelimitedText = editor->Text;
nodups->Duplicates = dupIgnore;
for(int i=0;i<soundfiles->Count;i++)
{
if(soundfiles->Strings[i].AnsiPos(".wav"))
{
nodups->Add(soundfiles->Strings[i]);
}
}
sflist->Items->Assign(nodups);
even though i have dupIgnore set nodups still keeps them there? Any ideas?
Rory.
 
 

Re:->Duplicates property...

Some snippets from the help which might be relevant:
"Set Duplicates to specify what should happen when an attempt is made
to add a duplicate string to a sorted list. The CaseSensitive property
controls whether two strings are considered duplicates if they are
identical except for differences in case."
Note the last sentence.
"Note:Duplicates does nothing if the list is not sorted"
So:Do you have CaseSensitive set appropriately and is the list sorted?
The example you posted is leaving both at set their default which I
think results in case sensitive comparing (probably good) but no
sorting (bad, for you).
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:->Duplicates property...

Cheers.
Rory.
Andrue Cope [TeamB] wrote:
Quote
Some snippets from the help which might be relevant:

"Set Duplicates to specify what should happen when an attempt is made
to add a duplicate string to a sorted list. The CaseSensitive property
controls whether two strings are considered duplicates if they are
identical except for differences in case."

Note the last sentence.

"Note:Duplicates does nothing if the list is not sorted"

So:Do you have CaseSensitive set appropriately and is the list sorted?
The example you posted is leaving both at set their default which I
think results in case sensitive comparing (probably good) but no
sorting (bad, for you).
 

{smallsort}

Re:->Duplicates property...

"Rory Walsh" < XXXX@XXXXX.COM >wrote in message
Quote
I am trying to remove duplicates from a ComboBox. I see that
TStringList has a duplicates property but I can't seem to be able
to use it right?
TComboBox does not support the Duplicates property. That is a feature
specific to TStringList, which TComboBox does not use. You will have to
copy the ComboBox Items to a separate TStringList, and then copy it back to
the ComboBox.
Also, the TStringList has to be Sorted in order for Duplicates to work.
For example:
TStringList* soundfiles = new TStringList;
soundfiles->Delimiter = ',';
soundfiles->DelimitedText = editor->Text;
TStringList* nodups = new TStringList;
nodups->Sorted = true;
nodups->Duplicates = dupIgnore;
for(int i = 0; i < soundfiles->Count; ++i)
{
if( AnsiSameText(ExtractFileExt(soundfiles->Strings[i], ".wav")) )
nodups->Add(soundfiles->Strings[i]);
}
sflist->Items->Assign(nodups);
Gambit