• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

TDragObject

How to correctly implement.
0
Diono
Asked:
Diono
  • 3
  • 2
1 Solution
 
rwilson032697Commented:
You will find all you need to know here:

http://www.melander.dk/delphi/dragdrop/

Cheers,

Raymond.
0
 
LischkeCommented:
Ray, please inform yourself a bit better. I'm a bit surprised about this and other quick shots which didn't hit the goal. TDragObject has nothing to do with OLE drag'n drop (for which you gave the link). Do I really need such a top expert like you to remind about proposing comments instead of answers?

Diono,

TDragObjects are mainly to give you a means to control how the drag'n drop stuff of the VCL happens. You can create your own descentant of TDragObject in the OnStartDrag event of a control. Usually this is not done and the VCL creates an internal object. In this case the OnDragOver and OnDragDrop events contain as Source parameter the control which initiated the drag'n drop operation. If you create your own drag object, though, then you get this object as Source parameter in the mentioned events. What you then do with this drag object is totally up to you. E.g. you could create one global drag object and pass it in every drag operation around but can store some sensible data in it which is needed by other controls while dragging.

Ciao, Mike
0
 
rwilson032697Commented:
Ouch Mike, stop spanking me so hard! :o)

Mike is right. I confused TDropTarget with TDragObject.

I'll withdraw the answer... If you really meant the drag/drop stuff I pointed you at you know what to do :-)

Cheers,

Raymond.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
LischkeCommented:
;-) didn't mean it hard...

Ciao, Mike

PS: This is the first answer withdraw I'
ve seen. Cool feature I think...
0
 
DionoAuthor Commented:
An example would've been great!
0
 
LischkeCommented:
Well, there's nothing special. Look at this code:

type
  TMyDragObject = class(TDragObject)
  protected
    procedure Finished(Target: TObject; X, Y: Integer; Accepted: Boolean); override;
  end;


  TMainForm = class(TForm)
  private
    FMyDragObject: TMyDragObject;
  end;


procedure TMainForm.ListBox1StartDrag(Sender: TObject; var DragObject: TDragObject);

begin
  if FMyDragObject = nil then FMyDragObject := TMyDragObject.Create;
  DragObject := FMyDragObject;
end;

{ TMyDragObject }

procedure TMyDragObject.Finished(Target: TObject; X, Y: Integer;
  Accepted: Boolean);
begin
  Beep;
  inherited;
end;

procedure TMainForm.FormDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := True;
end;

procedure TMainForm.FormDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if Source = FMyDragObject then ShowMessage('It''s mine');
end;


Ciao, Mike
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now