Insert text at cursus position

General TRichView support forum. Please post your questions here
Post Reply
Rkloeg
Posts: 2
Joined: Mon Jul 27, 2015 2:50 pm

Insert text at cursus position

Post by Rkloeg »

I have a RichviewEdit (already filled with text) and a Listbox with multiple items.

How can i drag and drop items from the ListBox and insert them onto the cursor position on the RichviewEdit?

I have made a start but this just add the string at the end...

Code: Select all

procedure TNotaPerEmailSettingsForm.RichViewEdit1DragDrop(Sender,
  Source: TObject; X, Y: Integer);
var s:string;
begin
  s:='<<'+
       FieldNamesBox.Items.Strings[FieldNamesBox.ItemIndex]+'>>';
  
with Source as TListBox do
    begin

      RichViewEdit1.add(s,0);

    end;
  RichViewEdit1.Format;
end;

Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

For an example of using VCL drag and drop in TRichViewEdit, see the demo in
Demos\DelphiUnicode\Assorted\Graphics\DragImg\
It shows how to drag an image from TImage to TRichViewEdit.
The example with text would be very similar, with InsertText instead of InsertPicture

---

Note that that demo uses VCL drag&drop implementation.
There is a way to use system drag&drop instead.
On the one hand, using system d&d is simpler, because it is supported by TRichView directly, and you do not need to position caret in events. On the other hand, system d&d requires writing quite low level code, if you do not have helper components. Such components exist, see http://www.trichview.com/forums/viewtopic.php?t=3407
Post Reply