Google喜欢Delphi的编辑/组合控制吗? [英] Google like edit/combo control for Delphi?
问题描述
每个人都可能知道我的意思,但要澄清控制将需要:
Everyone probably knows what I mean, but to clarify the control would need to:
- 在用户编辑文本时触发事件。该活动将提供SuggestionList:TStrings,您可以填写匹配/建议。
- 如果SuggestionList不为空,则会出现下拉菜单。
- 与组合不同,控件不应尝试自动选择/自动完成或以其他方式影响编辑。
编辑/组合控件。
推荐答案
使用自动完成功能。
首先,填充你的 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屋!