I want to add an string into specified place of a Memo Edit in delphi, how can I do this? I mean I want to know where the mouse cursor is within TMemo, and then add a string to this position. Is that possible?
You can use EM_CHARFROMPOS
to determine the character position of where the mouse cursor points:
var
Pt: TPoint;
Pos: Integer;
begin
Pt := Memo1.ScreenToClient(Mouse.CursorPos);
if (Pt.X >= 0) and (Pt.Y >= 0) then begin
Pos := LoWord(Memo1.Perform(EM_CHARFROMPOS, 0, MakeLong(Pt.x, Pt.Y)));
Memo1.SelLength := 0;
Memo1.SelStart := Pos;
Memo1.SelText := '.. insert here ..';
end;
end;