现在我需要有这样一个功能。
假设memo中有一段文字abcdefg,还有一个listbox里面有若干内容,现在我需要的功能是,首先鼠标在memo中点击需要添加内容的地方,假设点在c后面,然后我再双击listbox中的一项,假设为1111,这个时候1111的内容添加到memo中,memo的内容变为abc1111defg.这个怎么实现???

解决方案 »

  1.   

    转个例子--获得行号列号,下面就不用说了吧,对Memo.lines[]插入字符串1111
    var
      row, col: Integer;
      pt: TPoint;
    begin
      row := SendMessage(Memo1.Handle, EM_LINEFROMCHAR,
        Memo1.SelStart, 0);
      col := Memo1.SelStart -
        SendMessage(Memo1.Handle, EM_LINEINDEX, row, 0);
      Inc(row);  // 行号
      Inc(col);  // 列号
      ShowMessage(Format('%d 行 %d列',[row, col]));
    end;
      

  2.   

    转个例子--获得光标所在行号列号,下面就不用说了吧,对Memo.lines[]插入字符串1111
    var
      row, col: Integer;
      pt: TPoint;
    begin
      row := SendMessage(Memo1.Handle, EM_LINEFROMCHAR,
        Memo1.SelStart, 0);
      col := Memo1.SelStart -
        SendMessage(Memo1.Handle, EM_LINEINDEX, row, 0);
      Inc(row);  // 行号
      Inc(col);  // 列号
      ShowMessage(Format('%d 行 %d列',[row, col]));
    end;
      

  3.   

    public
      p: tpoint;procedure TForm1.Memo1Click(Sender: TObject);
    begin
      GetCaretPos(p);
    end;procedure TForm1.ListBox1DblClick(Sender: TObject);
    var
      temp: string;
      len: integer;
      i: integer;
      ch: char;
    begin
      temp := listbox1.Items[listbox1.ItemIndex];
      showmessage(temp);
      len := length(temp);
      memo1.SetFocus;
      SetCaretPos(p.X,p.Y);
      for i := 1 to len do
        sendmessage(memo1.Handle,wm_char,ord(temp[i]),0);
    end;
      

  4.   

    一句话即可:
    procedure TForm1.ListBox1DblClick(Sender: TObject);
    begin
      Memo1.SelText := ListBox1.Items[ListBox1.ItemIndex];
    end;