我要求备忘录自动完成功能。 最终,我希望能够在用户按下与Delphi IDE自动完成类似的热键(Ctrl-space)时显示自定义自动完成列表。德尔福 - 自动完成备忘录
我有TMS AdvMemo
,但说实话,这个特定组件的帮助是缺乏的。看来AdvMemo支持自定义自动完成,但我似乎无法找到如何显示列表。
因此,如果任何人有任何建议,将实现在备忘录自动完成,或者开导我,使用AdvMemo的,我们将不胜感激
我要求备忘录自动完成功能。 最终,我希望能够在用户按下与Delphi IDE自动完成类似的热键(Ctrl-space)时显示自定义自动完成列表。德尔福 - 自动完成备忘录
我有TMS AdvMemo
,但说实话,这个特定组件的帮助是缺乏的。看来AdvMemo支持自定义自动完成,但我似乎无法找到如何显示列表。
因此,如果任何人有任何建议,将实现在备忘录自动完成,或者开导我,使用AdvMemo的,我们将不胜感激
我决定使用TPopupmenu作为自动完成列表,为TMemo编写一些处理程序。
对于那些阅读,请参考我的另一篇: Delphi - Get the whole word where the caret is in a memo(感谢RRUZ)
以下代码: OnPopup为自动完成TPopupMenu:(memoAutoComplete持有自动完成的项目清单)
procedure AutoCompletePopup(Sender: TObject);
var i : integer;
NewItem : TMenuItem;
AutoCompleteToken: String;
begin
//filter list by token
AutoCompleteToken := SelectWordUnderCaret(edtComment);
AutoComplete.Items.Clear;
for i:=0 to memoAutoComplete.Lines.Count -1 do
begin
if SameText(LeftStr(memoAutoComplete.Lines.Strings[i],Length(AutoCompleteToken)),AutoCompleteToken) then
begin
NewItem := TMenuItem.Create(AutoComplete);
NewItem.Caption := memoAutoComplete.Lines.Strings[i];
NewItem.OnClick := AutoComplete1Click;
NewItem.OnMeasureItem := AutoComplete1MeasureItem;
NewItem.OnAdvancedDrawItem := AutoComplete1AdvancedDrawItem;
AutoComplete.Items.Add(NewItem);
end;
end;
end;
而对于Tmemo:
procedure Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var pt : TPoint;
begin
if (Key = VK_SPACE) and (GetKeyState(VK_CONTROL) < 0) then
begin
pt := Memo1.ClientToScreen(Point(0,Memo1.Height));
AutoComplete.Popup(pt.X,pt.Y);
end;
end;
+1创意使用的popupmenu。 – Johan 2011-06-14 19:24:41
也许最好的方式来获得一些帮助可能是联系组件供应商,而不是公开说它(或它的文档)*糟糕*? – 2011-06-14 02:26:46
我必须详细说明,其他TMS文档是好的,它只是这个特定的组件缺乏。 – Simon 2011-06-14 02:29:11