Is there an alternative to the OnChange event that occurs with any action in Delphi?

From the Delphi XE documentation: -

Note. OnChange occurs only in response to user actions. Changing the Text property does not programmatically raise the OnChange event.

Are there any other events available for TComboBox that occur when any changes occur (user or programmatically)? When the ItemIndex property changes in TComboBox, an event is not raised.

+6
source share
3 answers

The list control is sent CM_TEXTCHANGED when the text changes. The VCL control chooses not to draw an event here, but you could. There are many ways to do this. Here I illustrate a quick and dirty class of intermediate elements:

 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 will want to do this in a less dangerous way in your production code.

+8
source

You can always run the onchange method yourself if that is what you want.

 Edit1.Text := 'hello'; //Set a value Edit1.OnChange(Edit1); //..then trigger event 

Edit: David is right, TEdit calls OnChange in all updates. If this is the combobox you want to call, use the following: Combobox1.OnChange (Combobox1);

+3
source

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; 
+1
source

Source: https://habr.com/ru/post/902756/


All Articles