2011-06-14 55 views
4

我要求备忘录自动完成功能。 最终,我希望能够在用户按下与Delphi IDE自动完成类似的热键(Ctrl-space)时显示自定义自动完成列表。德尔福 - 自动完成备忘录

我有TMS AdvMemo,但说实话,这个特定组件的帮助是缺乏的。看来AdvMemo支持自定义自动完成,但我似乎无法找到如何显示列表。

因此,如果任何人有任何建议,将实现在备忘录自动完成,或者开导我,使用AdvMemo的,我们将不胜感激

+0

也许最好的方式来获得一些帮助可能是联系组件供应商,而不是公开说它(或它的文档)*糟糕*? – 2011-06-14 02:26:46

+0

我必须详细说明,其他TMS文档是好的,它只是这个特定的组件缺乏。 – Simon 2011-06-14 02:29:11

回答

5

我决定使用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; 
+0

+1创意使用的popupmenu。 – Johan 2011-06-14 19:24:41

3

你可以看看SynEdit。它是免费的,开源的,并有一个积极的社区,以帮助你当你陷入困境。

+0

该组件是否有任何文档?我无法看到页面上的任何内容 – Simon 2011-06-14 06:04:13

+0

我无法在网站上找到文档。我只会安装它并使用这些功能。如果卡住了,请浏览支持新闻组和论坛。 – Birger 2011-06-14 06:33:15