Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-03

TComboBox and OnChange

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Fuchs

Hello,

a little problem with the OnChange-Event of the TComboBox.

If the user selects a item from the drop-down-list, OnChange is called. If the user places the cursor in the combobox and types a text, OnChange is also called.

But if I set the text with the .Text-property [1], OnChange is NOT called.

If i substitute the TComboBox with a TEdit, setting the .Text-property causes an OnChange-call.

I know that this behaviour is the same as in Delphi, but I think it is not consistent. Is it possible to change this?

regards
Michael

Reply by email

dmitry boyarintsev
to Michael Fuchs
Michael Fuchs wrote
I know that this behaviour is the same as in Delphi, but I think it is not consistent. Is it possible to change this?

Why the behavior is not consistent?

Since your code has changed Text value you're aware of the change happened. So you can call the necessary change handling code, like:

ComboBox1.Text:='something';
ComboBox1Change(ComboBox1Text);

thanks,
dmitry

Reply by email

Michael Fuchs
to dmitry boyarintsev
dmitry boyarintsev wrote 6 lines
On Wed, Mar 24, 2010 at 4:42 PM, Michael Fuchs wrote: > I know that this behaviour is the same as in Delphi, but I think it is not > consistent. Is it possible to change this? Why the behavior is not consistent?

Because, if you try this with a TEdit, it works.

Show quoted text 5 lines
Since your code has changed Text value you're aware of the change happened. So you can call the necessary change handling code, like: ComboBox1.Text:='something'; ComboBox1Change(ComboBox1Text);

Yes, in my case I try to test the OnChange calling in a fpcunit test. The user selects a item of the dropdown list or types in text, but the test just change the .Text property.

regards
Michael

Reply by email

zeljko
to Michael Fuchs
Michael Fuchs wrote 20 lines
Am 24.03.2010 15:33, schrieb dmitry boyarintsev: > On Wed, Mar 24, 2010 at 4:42 PM, Michael Fuchs > > wrote: >> I know that this behaviour is the same as in Delphi, but I think it is >> not consistent. Is it possible to change this? > > Why the behavior is not consistent? Because, if you try this with a TEdit, it works. > Since your code has changed Text value you're aware of the change > happened. So you can call the necessary change handling code, like: > > ComboBox1.Text:='something'; > ComboBox1Change(ComboBox1Text); Yes, in my case I try to test the OnChange calling in a fpcunit test. The user selects a item of the dropdown list or types in text, but the test just change the .Text property.

so if user types text it'll call OnChange() for each char like in TEdit ? hm...I don't like it.
Does work this (cannot try at the moment) ?
i := ComboBox1.Items.Add('something');
ComboBox1.ItemIndex := i;
OnChange() should fire on itemindex change if I remember correctly.

zeljko

Reply by email

Michael Fuchs
to zeljko

zeljko:

so if user types text it'll call OnChange() for each char like in TEdit ?

Yes.

hm...I don't like it.

Why not?

Does work this (cannot try at the moment) ? i := ComboBox1.Items.Add('something'); ComboBox1.ItemIndex := i; OnChange() should fire on itemindex change if I remember correctly.

No, this also didn't work.

bye
Michael

Reply by email

zeljko
to Michael Fuchs
Michael Fuchs wrote 8 lines
zeljko: > so if user types text it'll call OnChange() for each char like in TEdit ? Yes. > hm...I don't like it. Why not?

1. It breaks delphi compatibility
2. It breaks current apps which rely on combo OnChange() like dmitry stated eg.
MyCombo.Text := 'blah';
MyComboChange(MyCombo);
So if such combo have OnChange() assigned it'll fire twice. Problem is not in small apps, but apps with hundreds of forms and hundreds of combos are real PITA.

In your case I'll prefer to add new event OnComboTextChange instead of firing text changes in OnChange().

zeljko

Reply by email

Hans-Peter Diettrich
to zeljko
Show quoted text 8 lines
>> so if user types text it'll call OnChange() for each char like in TEdit ? > Yes. > >> hm...I don't like it. > Why not? 1. It breaks delphi compatibility 2. It breaks current apps which rely on combo OnChange() like dmitry stated

Then the behaviour could be changed by a (global) option, for Delphi or Lazarus compatibility.

DoDi

Reply by email