Recent

Author Topic: Combobox : No Duplicates  (Read 649 times)

Petrus Vorster

  • Jr. Member
  • **
  • Posts: 59
Combobox : No Duplicates
« on: July 25, 2024, 03:17:09 pm »
Hi All

Making progress on learning the new Syntax. Slow but steady!

I am populating a combobox (autocomplete and autodropdown on) with phone numbers.
This is so that if you type the number again, the autocomplete and dropdown will make suggestions.
This works great.

How do I prevent duplicate entries in that combobox?
The phone number is being added to the combobox after you typed phone number and press tab. It is pointless of having a few of the same phone number clogging the control.

Thank you for the patience. A lot of questions still coming.

Regards, Peter

Zvoni

  • Hero Member
  • *****
  • Posts: 2614
Re: Combobox : No Duplicates
« Reply #1 on: July 25, 2024, 03:44:28 pm »
The Items-Property of a TComboBox is a TStrings, which has an "IndexOf"-Function
https://lazarus-ccr.sourceforge.io/docs/lcl/stdctrls/tcombobox.html
https://lazarus-ccr.sourceforge.io/docs/rtl/classes/tstrings.indexof.html

Before you add the entry to the ComboBox-Items check if IndexOf of the entered text is greater than -1.
If yes, then it already exists and you skip adding it, if no then add
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Petrus Vorster

  • Jr. Member
  • **
  • Posts: 59
Re: Combobox : No Duplicates
« Reply #2 on: July 25, 2024, 04:09:16 pm »
WOW. SO simple!
I would have written an entire loop in Freebasic.

Although I am a complete newby here, I have to admit that although the syntax is strange to me, it is darn powerful. I started here last week and already have a number of processes running.

Great stuff.

-Peter

jamie

  • Hero Member
  • *****
  • Posts: 6516
Re: Combobox : No Duplicates
« Reply #3 on: July 25, 2024, 04:39:50 pm »
if you are examining The EDIT line, (TEXT), you can use the POS function which returns a non -1 if the char exists in the string.

 
The only true wisdom is knowing you know nothing

Zvoni

  • Hero Member
  • *****
  • Posts: 2614
Re: Combobox : No Duplicates
« Reply #4 on: July 26, 2024, 07:59:51 am »
if you are examining The EDIT line, (TEXT), you can use the POS function which returns a non -1 if the char exists in the string.
What's that got to do with TS' issue?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018