delphi - 带有 ComboBox 的 IAutoComplete 不会触发 OnChange 事件
问题描述
精简版
当组合框中的文本发生更改时,如何触发OnChange事件?
长版
我正在使用IAutoComplete2将“自动建议”(即下拉)列表添加到组合框。
当用户在建议列表中选择不同的选项时,组合框中的文本会发生变化,但遗憾的是没有触发OnChange事件:
将AutoComplete附加到裸TEdit时,会触发OnChange事件。
function SHAutoCompleteComboShell(AComboBox: TComboBox): IAutoComplete2;
var
cbi: TComboBoxInfo;
hEdit: HWND; //A handle to the edit box.
strings: IEnumString;
ac: IAutoComplete2;
const
Default_TComboBoxInfo: TComboBoxInfo = ();
begin
//Example public domain pseudocode on how to autocomplete a combobox.
Result := nil;
if AComboBox = nil then
Exit;
//Get the EDIT control inside the Combobox
cbi := Default_TComboBoxInfo;
cbi.cbSize := sizeof(TComboBoxInfo);
if not GetComboBoxInfo(AComboBox.Handle, {var}cbi) then
Exit;
hEdit := cbi.hwndItem; //A handle to the edit box.
if hEdit = 0 then
Exit;
//Suggest strings from the shell namespace
strings := CreateComObject(CLSID_ACListISF) as IEnumString;
ac:= CreateComObject(CLSID_IAutoComplete) as IAutoComplete2;
ac.Init(hEdit, strings, nil, nil);
ac.SetOptions(ACO_AUTOSUGGEST);
Result := ac;
end;
即使用户最终Enter选择一个选项,TComboBox 的OnChange仍然不会触发。
我假设 Windows编辑控件正在发送一条EN_CHANGE通知消息,说明其文本已更改;但 TComboBox 并不关心。
当然,TComboBox 很有csDropDown
风格(否则我为什么要问这个问题)。
试过Delphi 5,Delphi XE6
解决方案
推荐阅读
- ruby-on-rails - 为什么 Rails 应用程序没有收到来自 EC2 上的 google drive API 的请求响应,但它在 localhost 中工作?
- docker - 使用 docker stack deploy 启动时在 Kubernetes 中使用私有注册表 docker 映像
- asp.net-core - Syncfusion html-pdf 与 JsReoprt html-pdf。哪个更好?
- sql - 从两个表中提取数据
- xslt - 复制后展平 XML
- python - 打开共享对象文件失败
- javascript - 在按钮单击时将时间戳传递给表单
- python-3.x - 写入 csv 文件时,标题每隔一行重复一次
- regex - Makefile 变量 - 替换变量中的空格
- mysql - 嵌套游标声明问题 Mysql