From the Delphi XE documentation:-
Note: OnChange only occurs in response to user actions. Changing the Text property programmatically does not trigger an OnChange event.
Are there any other events available for TComboBox that are raised when any change happens (by the user or programmatically)? When changing the ItemIndex property of the TComboBox no event is raised.
The combo box control is sent a CM_TEXTCHANGED
when the text is modified. The VCL control chooses not to surface an event here, but you could. There's many ways to do so. Here I illustrate the quick and dirty interposer class:
TComboBox = class(Vcl.StdCtrls.TComboBox)
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
end;
procedure TComboBox.CMTextChanged(var Message: TMessage);
begin
inherited;
Beep;
end;
Naturally you would want to do this in a less hacky way in your production code.
You could always trigger the onchange-method yourself if that's what you want.
Edit1.Text := 'hello'; //Set a value
Edit1.OnChange(Edit1); //..then trigger event
Edit: David is right, a TEdit calls OnChange on all updates. If it is a combobox you want to trigger then use something like: Combobox1.OnChange(Combobox1);
Create a new component from TComboBox
TMyCombo= class(TComboBox)
private
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
end;
{ TMyCombo }
procedure TMyCombo.CMTextChanged(var Message: TMessage);
begin
inherited;
Change;
end;
TForm1 = class(TForm)
procedure MyChange(sender: TObject);
...
private
FCombo: TMyCombo;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
FCombo:= TMyCombo.Create(self);
FCombo.Parent:= self;
FCombo.OnChange:= MyChange;
end;
procedure TForm1.MyChange(Sender: TObject);
begin
self.Edit1.Text:= FCombo.Text;
end;
destructor TForm1.Destroy;
begin
FreeAndNil(FCombo);
inherited;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With