Solved

Drag & Drop

Posted on 1997-10-26
11
224 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
Convert Jpg /PNG To GIF 5 103
FMX enumerated colours 2 72
FMX and jaudiotracker playing memory stream 29 36
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now