Page 1 of 1

Insert text at cursus position

Posted: Mon Jul 11, 2016 3:22 pm
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;


Posted: Mon Jul 11, 2016 6:54 pm
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