好象getcaretpos就可以得到一个tpoint,随着光标的移动变化..但如何通过这个值在memo中创建一个值比如 combobox就象delphi的ide一样, 输入个点..就出来选择的那种..
不需要synedit之类的吧..

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TDemo = class(TForm)
        M: TMemo;
        LB: TListBox;
        procedure MKeyPress(Sender: TObject; var Key: Char);
        procedure LBKeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
        procedure FormCreate(Sender: TObject);
      private
        procedure Popup;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Demo: TDemo;implementation
    uses Clipbrd;
    {$R *.dfm}procedure TDemo.MKeyPress(Sender: TObject; var Key: Char);
    var P:TPoint;
    begin
     if Key='.' then
     begin
       Popup;
     end;
    end;procedure TDemo.Popup;
    var
      AWord : String;
      FirstVisibleLine : LongInt;
      ATextSize:TSize;
      DC:HDC;
      AString:String;
      P:TPoint;
    begin
      P:=M.CaretPos;
      AString:=Copy(M.Lines[P.Y],1,P.X);
      FirstVisibleLine := SendMessage(M.Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
      DC:=GetWindowDC(M.Handle);
      try
         SelectObject(DC,M.Font.Handle);
         GetTextExtentPoint(DC,PChar(AString),Length(AString),ATextSize);
      finally
        ReleaseDC(M.Handle,DC);
      end;
      LB.Top:=M.Top+ATextSize.cy * (P.Y - FirstVisibleLine+1)+4;
      LB.Left:=M.Left+ATextSize.CX;
      LB.BringToFront;
      LB.Show;
      Self.ActiveControl:=LB;
      LB.ItemIndex:=0;
    end;procedure TDemo.LBKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key=VK_Return then
      begin
        if LB.ItemIndex<>-1 then
        begin
          Clipboard.AsText:=LB.Items[LB.ItemIndex];
          M.PasteFromClipboard;
        end;
        LB.Hide;
       ActiveControl:=M;
      end;
    end;procedure TDemo.FormCreate(Sender: TObject);
    begin
      
      with LB.Items do
      begin
         Add('这是第一行');
         Add('这是第二行');
         Add('这是第三行');
         Add('这是第四行');
         Add('这是第五行');
         Add('这是第六行');
         Add('这是第七行');
         Add('这是第八行');
         Add('这是第九行');
      end;
    end;end.
      

  2.   

    忘记贴form了。补上。object Demo: TDemo
      Left = 215
      Top = 107
      Width = 696
      Height = 480
      Caption = 'Demo'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object M: TMemo
        Left = 50
        Top = 14
        Width = 450
        Height = 341
        Lines.Strings = (
          'M')
        TabOrder = 0
        OnKeyPress = MKeyPress
      end
      object LB: TListBox
        Left = 42
        Top = 43
        Width = 87
        Height = 97
        Ctl3D = False
        ItemHeight = 13
        Items.Strings = (
          '111111'
          '222222'
          '333333'
          '444444'
          '555555')
        ParentCtl3D = False
        TabOrder = 1
        Visible = False
        OnKeyDown = LBKeyDown
      end
    end