Page 1 of 1

Drag and Drop - Help

Posted: Mon May 14, 2012 12:21 pm
by alexandreq
Hello Sergey,

How could you do a drag and drop word this way?

I have a listbox and I want to get a word from DBSrichviewEdit and drop only a copy of my word into my ListBox.

how could you do that?

thanks
Alex

Posted: Mon May 14, 2012 1:55 pm
by alexandreq
Sergey, I tried this and I didn't have any success:

Code: Select all

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  re: TDBSRichViewEdit;
  lb: TListbox;
begin
  if (Source is TDBSRichViewEdit) and (Source <> nil) then
  begin
    re := TDBSRichViewEdit(Source);
    if (Sender is TListbox) and (Sender <> nil) then
    begin
      lb := TListBox(Sender);
      lb.Items.Add(re.RichViewEdit.GetSelText);
    end;
  end;

end;

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
   Accept := Source = DBSRichViewEdit1.RichViewEdit;
end;



And I settled

DBSRichViewEdit1.RichViewEdit.DragMode := dmAutomatic

With a RichEdit worked fine, unfortunately it didn't with DBSrichViewEdit

Posted: Fri May 18, 2012 2:18 pm
by Sergey Tkachenko
You cannot drag RichViewEdits inside TSRichViewEdit.
You can only drag TSRichViewEdit itself.
Unfortunately, TSRichViewEdit.DragMode is not published, it is protected. Open SclRView.pas and add property DragMode; to the published section of TSRichViewEdit.

However, after making the editor draggable, it becomes inconvenient to edit it.

Alternatively, you can use the "real" system drag&drop (instead of VCL drag&drop), it is supported natively by TSRichViewEdit.
However, when accepting this kind of drag&drop, you only have access to data (such as text) provided by the editor. You cannot distinguish if data were dragged from this TDBSRichViewEdit, or another TSRichViewEdit, or from another copy of your application, or from another application (such as a browser or MS Word). If it is ok, I can create a demo.

Posted: Fri May 18, 2012 3:40 pm
by alexandreq
Hi Sergey

Yeah, it is ok for me.

You can create an example as you told that it will be suitable for me. I just need to drag from DBSRichViewEdit to a listBox the word

Posted: Sat May 19, 2012 4:19 pm
by Sergey Tkachenko
Using OLE drag&drop requires writing some "low level" code implementing IDropTarget interface.

But there is a ready-to-use solution: Drag and Drop Component Suite by Anders Melander: http://melander.dk

The example is here:
http://www.trichview.com/forums/viewtopic.php?t=3407
It is for TRichViewEdit, but for TSRichViewEdit it is the same. This listbox can accept text from all sources.