?
Solved

Drag & Drop

Posted on 1997-10-26
11
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Accepted Solution

by:
sassas081597 earned 400 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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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