Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread ButtonComboBox.Items.IndexOfValue
Wed, Oct 28 2015 5:46 AMPermanent Link

Petter Topp

It seems that this method as well as IndexOf and IndexOfName always returns -1

Four strings were added at design time: 'One', 'Two', 'Three' and 'Four'.

ShowMessage(IntToStr(ButtonComboBox1.Items.IndexOfValue('One')));

Am I missing something or is this a bug?

Petter
Wed, Oct 28 2015 6:05 AMPermanent Link

Matthew Jones

Petter Topp wrote:

> IndexOfValue

Typo? The value is a different thing IIRC, used for the "One=Hello"
type use.

--

Matthew Jones
Wed, Oct 28 2015 6:33 AMPermanent Link

Petter Topp

Hi Matthew.

What do you mean?

P
Wed, Oct 28 2015 7:58 AMPermanent Link

Matthew Jones

Your code specifically has IndexOfValue but that isn't what you want
here. You are adding plain strings, like "One" so you need IndexOf, not
IndexOfValue, which is used for "INI" style name=value pairs. Since you
don't have such pairs, it will indeed return -1.

--

Matthew Jones
Wed, Oct 28 2015 9:00 AMPermanent Link

Rick

On 28/10/15 20:46, Petter Topp wrote:
> It seems that this method as well as IndexOf and IndexOfName always returns -1
>
> Four strings were added at design time: 'One', 'Two', 'Three' and 'Four'.
>
> ShowMessage(IntToStr(ButtonComboBox1.Items.IndexOfValue('One')));
>
> Am I missing something or is this a bug?

I set up a similar scenario and using IndexOf('One') returned '0' in the
ShowMessage which is what I expected. Changing the search string to the
other values also returned the correct index numbers.

I don't think IndexOf() is case sensitive but you might want to check
that along with embedded spaces, only one item per line in the IDE
designer, etc.

I'm assuming that when you drop down the combobox you see all of your
values.

--
Rick
Wed, Oct 28 2015 9:35 AMPermanent Link

Raul

Team Elevate Team Elevate

On 10/28/2015 5:46 AM, Petter Topp wrote:
> It seems that this method as well as IndexOf and IndexOfName always returns -1

IndexOf works fine here - it's not even case sensitive so

"ButtonComboBox1.Items.IndexOf('one'))" returns 0 as expected (entry is
"One" in items list).


> Four strings were added at design time: 'One', 'Two', 'Three' and 'Four'.
> ShowMessage(IntToStr(ButtonComboBox1.Items.IndexOfValue('One')));
> Am I missing something or is this a bug?

for any of the Value and Names type function you need to have pairs i.e.

   ButtonComboBox1.Items.clear;
   ButtonComboBox1.Items.add('One=1');
   ButtonComboBox1.Items.add('Two=2');
   ButtonComboBox1.Items.add('Three=3');
   ButtonComboBox1.Items.add('Four=4');

and now

"ButtonComboBox1.Items.IndexOfName('one')) return 0 (as expected)

and

ButtonComboBox1.Items.IndexOfValue('3') returns 2 as expected.

You can also use Names and Values to do something like

ButtonComboBox1.Items.names [ ButtonComboBox1.Items.IndexOfValue('3') ]
- returns "Three".

Raul
Thu, Oct 29 2015 6:10 AMPermanent Link

Petter Topp

You are all correct - IndexOf works just fine.
Can't explain what happened here, stared off using IndexOf, but couldn't get it to work...

Petter
Image