Page 1 of 1

Inserting Text or Items at cursor position

Posted: Fri May 08, 2009 9:33 am
by semike
Hello Sergey,

how can I insert a text or an item at a given cursor position (x, y). When I've got a "simple" Text (no tables) my code
> GetItemAt(...)
> SetSelectionBounds(...)
> InsertSomething
works rather fine. But when the existing text contains tables or nested tables my code always adds the text on end of the first item - in most cases before the table.

How do I correctly insert a text on a cursor position? I'll use this code when I drag a VCL component onto the text.

Thank you!

Posted: Fri May 08, 2009 6:59 pm
by Sergey Tkachenko

Code: Select all

// X, Y - client coordinates

var LRVData: TCustomRVFormattedData;
    LItemNo, LOffs: Integer;
    pt: TPoint;

  pt := rve.ClientToDocument(Point(X,Y));
  if not rve.GetItemAt(pt.X, pt.Y, LRVData, LItemNo, LOffs, True) then
    exit;
  LRVData := TCustomRVFormattedData(LRVData.Edit);
  LRVData.SetSelectionBounds(LItemNo, LOffs, LItemNo, LOffs);
  Insert something