5

I am requiring a Memo with Auto-completion functionality. Ultimately, I would like the ability to display a custom auto-completion list when the user presses a hotkey (Ctrl-space) similar to Delphi IDE auto-completion.

I have the TMS AdvMemo, but to be honest the help for this particular component is lacking. It appears the AdvMemo supports custom auto completion, but I cant seem to find out how to display a list.

So, if anyone has any suggestions to achieve auto completion on a memo, or to enlighten me as the use of the AdvMemo, it would be appreciated

RBA
  • 12,337
  • 16
  • 79
  • 126
Simon
  • 9,197
  • 13
  • 72
  • 115
  • Perhaps the best way to get help for something might be to contact the component vendor instead of publicly saying it (or it's docs) *sucks*? – Ken White Jun 14 '11 at 02:26
  • 1
    I must elaborate, other TMS docs are good, its just this particular component is lacking. – Simon Jun 14 '11 at 02:29

2 Answers2

7

I decided to write some handlers for a TMemo using a TPopupmenu as the autocomplete list.

For those that read this please refer to my other post: Delphi - Get the whole word where the caret is in a memo (thanks to RRUZ)

And the following code: OnPopup for the AutoComplete TPopupMenu: (memoAutoComplete hold the list of autocomplete items)

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;

And for the 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;
Community
  • 1
  • 1
Simon
  • 9,197
  • 13
  • 72
  • 115
4

You can have a look at SynEdit. It's free, open source and has an active community to help you out when you get stuck.

Birger
  • 4,343
  • 21
  • 35
  • Is there any documentation for this component? I couldnt see any on the page – Simon Jun 14 '11 at 06:04
  • I can't find the documentation on the site. I would just install it and play around with the features. If you're stuck, browse the support newsgroups and forums. – Birger Jun 14 '11 at 06:33
  • Drop a TSynCompletionProposal component. Set the stringlists for suggestion keywords. Set the hotkey and the trigger character. Select the target component as a synedit/synmemo and autocomplete is available. – user30478 Dec 09 '18 at 17:13