Google 喜欢 Delphi 的编辑/组合控件吗? [英] Google like edit/combo control for Delphi?

查看:30
本文介绍了Google 喜欢 Delphi 的编辑/组合控件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人可能都知道我的意思,但要澄清控制需要:

Everyone probably knows what I mean, but to clarify the control would need to:

  • 当用户编辑文本时触发一个事件.该事件将提供一个 SuggestionList: TStrings,您可以在其中填充匹配/建议.
  • 如果 SuggestionList 不为空,则会出现一个下拉列表.
  • 与组合不同,控件不应尝试自动选择/自动完成或以其他方式影响编辑.

那么,有没有像这样工作的 Delphi 编辑/组合控件?

So, is there a Delphi edit/combo control that works like that ?

推荐答案

使用 自动完成功能内置于所有 Windows 编辑控件中.

Use the autocompletion feature built in to all Windows edit controls.

首先,根据需要填充TStrings 对象.然后使用 GetOleStrings 创建一个 TStringsAdapter 来包装它.(适配器不声明对 TStrings 对象的所有权,因此您必须确保在适配器仍然有效时不要销毁它.)适配器给您一个 IStrings 界面,您将需要该界面,因为自动完成功能需要 IEnumString 接口提供完成匹配.为此调用 _NewEnum.

First, fill your TStrings object however you want. Then use GetOleStrings to create a TStringsAdapter to wrap it. (The adapter does not claim ownership of the TStrings object, so you must make sure you don't destroy it while the adapter is still live.) The adapter gives you an IStrings interface, which you'll need because the autocompletion feature requires an IEnumString interface to provide the completion matches. Call _NewEnum for that.

接下来,调用 CoCreateInstance 以创建一个 IAutoComplete 对象.调用它的 Init 方法将其与编辑控件的窗口句柄.如果您使用的是组合框,请向其发送 cbem_GetEditControl 消息以查找底层编辑窗口.

Next, call CoCreateInstance to create an IAutoComplete object. Call its Init method to associate it with the window handle of your edit control. If you're using a combo box, then send it a cbem_GetEditControl message to find the underlying edit window.

您可以在此时停止,自动完成应该会自动运行.您可以根据需要禁用自动完成功能,也可以设置任意数量的自动完成选项.

You can stop at that point and autocompletion should work automatically. You can disable autocompletion if you want, or you can set any number of autocompletion options.

您说您不想要自动完成,但在操作系统术语中,我认为您真正不想要的是自动附加,其中将字符串的其余部分输入到编辑中框在用户键入时自动,但被选中以便进一步键入将覆盖它,如果所需的值比匹配项之一短,则用户需要删除多余的文本.

You say you don't want autocompletion, but in the OS terminology, I think what you really don't want is called auto append, where the remainder of the string is entered into the edit box automatically as the user types, but selected so that further typing will overwrite it, and the user needs to delete the excess text if the desired value is shorter than one of the matches.

还有自动建议,显示建议的下拉列表.

There is also auto suggest, which displays a drop-down list of suggestions.

您可以启用一个或两个选项.您不需要自己过滤建议列表;自动完成对象自己过滤 IEnumString 列表.

You can enable either or both options. You don't need to filter the list of suggestions yourself; the autocomplete object filters the IEnumString list by itself.

这篇关于Google 喜欢 Delphi 的编辑/组合控件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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