Drag and Drop - Help

General TRichView support forum. Please post your questions here
Post Reply
alexandreq
Posts: 184
Joined: Wed Jan 18, 2012 6:22 pm

Drag and Drop - Help

Post 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
alexandreq
Posts: 184
Joined: Wed Jan 18, 2012 6:22 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17560
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
alexandreq
Posts: 184
Joined: Wed Jan 18, 2012 6:22 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17560
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply