Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Drag & Drop

Posted on 1997-10-26
11
Medium Priority
?
233 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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