Solved

Drag & Drop

Posted on 1997-10-26
11
228 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
Technology Partners: 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!

 
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
 
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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 101
When i run adoquery my application freezes 26 192
Tvertscrollbox like a whatsapp layout 5 54
Problem working with dynamic array - help 2 36
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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