Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

TScreen.ScreenDragOver ?

Want to do something during draging but don't want to put the code into the OnDragOver events of all the controls (too many) in a form and the form itself.

Can you find or make an event or similar:
  TScreen.ScreenDragOver (....X, Y: Integer..)
so that one may
1. do something based on the coordinates of the cursor in anywhere of the form during the draging;
2. stop doing that when this draging finished.
0
zhuhail
Asked:
zhuhail
  • 5
  • 3
1 Solution
 
zhuhailAuthor Commented:
Edited text of question
0
 
zhuhailAuthor Commented:
Edited text of question
0
 
zodikCommented:
You can create one OnDragOver proc, assign it to all the components of the form, and make the processing based
on source component, or call  GetCursorPos and use X,Y coordinates.

General idea is that you can assign ONE event proc to multiple events.
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!

 
zhuhailAuthor Commented:
Hi again,

I just think what you suggested was sharing one event by all
the controls in the form. That will be fine.

However, in my case there are many controls ....I don't want
to connect all the controls to the event by hand in design
time: I may miss one or two controls and, especially, when
add a new control later I may forget to do this:-)

Is this possible to put the OnDragOver event into a new
component and all the controls in the form and the form
itself can be automatically connected with it as long as
the new component is put to the form in design time?  

Cheers.
0
 
zhuhailAuthor Commented:
sure, no problem. just do something like this :


  for I:= 0 to Form1.ControlCount -1 do
     Form1.Controls[I].OnDragOver := TForm1.FormDragOver;

0
 
zodikCommented:
Hi,

That is great.

I have tried put your code into the OnCreate event of the
form, but got error message:
   Undeclared identifier: 'OnDragOver'
Anything wrong I did?

Cheers.
0
 
zhuhailAuthor Commented:
sorry, my mistake. OnDragOver is declared protected in TControl,
so you can not change it.
if you know the type of components in advance, you can do something like this:
for I:= 0 to Form1.ControlCount -1 do
   if (Controls[I] is TEdit) then
      (Controls[I] as TEdit).OnDragOver := FormDragOver;

if not, you can select "view as text" and paste 'OnDragOver  = FormDragOver' in each component (easier the selecting in object inspector).
0
 
zodikCommented:
Create a component

TControlHack = class(TControl)
public
  property OnDragOver;
end;


Then use zodiks solution, but change it to

TControlHack(Form1.Controls[I]).OnDragOver := TForm1.FormDragOver

This should work.

Regards,

Erik.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now