Solved

Drag & Drop

Posted on 1997-10-26
11
226 Views
Last Modified: 2010-04-04
I am using D1.  I need a code snippet for dragging and dropping an object,
but I want to be able to see the object while it is being dragged.  I have
looked at the source code for aps that use d & d, but I have not been able
to get my ap to do what I want it to.



 
0
Comment
Question by:jdthedj
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:olmy
ID: 1348910
Do you want to see something more than the dragging cursor?

0
 
LVL 3

Author Comment

by:jdthedj
ID: 1348911
Hi Olmy

Yes, I need to see the object that I am dragging on the move.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1348912
Do you want to see the component itself or the contour, just like in Delphi design mode ?
Also, do you have a component TShape in Delphi 1 ?
0
 
LVL 1

Accepted Solution

by:
sassas081597 earned 100 total points
ID: 1348913
Do not use OnDragDrop event.
Add a public field IsDragged to a component.
In OnMouseDown event handler change the IsDragged property of the component in whose region the mouse was Down.
In OnMouseMove event handler look if a component is Dragged and repaint the component on a new place accordingly the Mouse Movement:

procedure TheLabel.OnMouseDown(...);
begin
TheLabel.IsDragged:=true;
end;

procedure TheLabel.OnMouseMove(...X,Y,...);
begin
if TheLabel.IsDragged=true then
begin
TheLabel.Left:=X;
TheLabel.Top:=Y;
end;
end;

procedure TheLabel.OnMouseUp(...);
begin
TheLabel.IsDragged:=false;
end;

Of course, you can in onMouseDown calculate also the distance between the mouse and the topleft corner of the component and add it to Top and Left in OnMouseMove.
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1348914
Thanks for the reply Sassas.

I need some more help on the last bit.  How do I work out the
coordinates, and how do I stop leaving a trail?  My experiments
so far have left a big mess on the screen.  I will increase the
points to 100 for this extra help.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:itamar
ID: 1348915
Sorry for the insistency, but...
Do you want to see the component itself or the contour, just like in Delphi design mode ?
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1348916
Hi Itamar

I need to see the component itself.
0
 
LVL 1

Expert Comment

by:sassas081597
ID: 1348917
Hi jdthedj!
I'm sorry but I do not speek English that good to understand what do you ask. Can you reask your question with other words if I do not answer your question? I do not understand the following words: Leaving a Trail and Big Mess.

As I understood, you 'd like to have the coordinates of the mouse. They are given to you in OnMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer).
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1348918
Hi Sassas

Thank you for replying.

What I need to know is when I move the component, how do I erase
it from where it is before moving it.

Also do I move it using coordinates X+1, Y+1
0
 
LVL 1

Expert Comment

by:sassas081597
ID: 1348919
When you move the component it should erase itself. If it does not you can force the repaiting by using Repaint (or Invalidate) method of the Form in your method.
You can use every coordinates you'd like.
If you declare two variables L,T: Integer you can have the following meyhods:

procedure TheLabel.OnMouseDown(...);
begin
L:=TheLabel.Left-x;
T:=TheLabel.Top-y;
IsDragged:=True;
end;

procedure TheLabel.OnMouseMove(...);
begin
if IsDragged then
begin
TheLabel.Left:=L+x;
TheLabel.Top:=T+y;
end;
end;

0
 
LVL 3

Author Comment

by:jdthedj
ID: 1348920
Thank you Sassas - It works!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now