Delphi-更改TComboBox的OnChange [英] Delphi - Changing TComboBox's OnChange

查看:234
本文介绍了Delphi-更改TComboBox的OnChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 TComboBox ,以便如果我在其中键入文本或手动设置Text属性,它将触发 OnChange 事件。



现在,执行 ComboBox.Text:='blah'不会'不会触发 OnChange 事件,也不会在框中键入内容。



我尝试创建 TComboBox 后代,我认为这是正确的方法,但是我不确定如何更改触发事件的方式。

据我所知,在组合框中键入内容将导致 OnChange 事件触发。



我将如何启动 OnChange 的方式您的组合框将处理 CM_TEXTCHANGED 消息。为此,处理程序需要调用 Change 方法,如果已分配<< c $ c> OnChange ,则该方法将调用 OnChange



作为一个简单的示例,这是一个插入器类实现:

  type 
TComboBox = class(StdCtrls.TComboBox)
受保护的
过程CMTextChanged(var Message:TMessage);消息CM_TEXTCHANGED;
结尾;

过程TComboBox.CMTextChanged(var Message:TMessage);
开始
继承;
零钱;
结尾;


I want to change the TComboBox so that if I type text into it or manually set the Text property it will trigger the OnChange event.

As it is now, doing ComboBox.Text := 'blah' doesn't trigger the OnChange event, nor does typing into the box.

I tried creating a TComboBox descendant, which I assume is the right approach, but I'm not really sure how to change what triggers the events.

解决方案

To the best of my knowledge, typing into a combo box will result in the OnChange event firing. But it is true that modifying the text property does not.

The way I would go about getting OnChange to fire for your combo box is to handle the CM_TEXTCHANGED message. The handler for this needs to call the Change method which will then call OnChange, if it has been assigned.

As a simple example, here's an interposer class implementation:

type
  TComboBox = class(StdCtrls.TComboBox)
  protected
    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  end;

procedure TComboBox.CMTextChanged(var Message: TMessage);
begin
  inherited;
  Change;
end;

这篇关于Delphi-更改TComboBox的OnChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆