Board index » delphi » Setting OnMouseMove Event at Runtime

Setting OnMouseMove Event at Runtime

I have declared an array of TImage controls.  I need to be able to
assign code to it's onMouseMove Event.  I have tried everything I know
to get this to work, but I do not know how to pass the event the
TShiftState parameter.

Also is there anyway of referencing a control by using :

procedure Form1.Example(Sender: TObject);
begin
   Sender.Left := 250;
end;

If anybody could help me with these problems, it would be greatly
appreciated.

Regards,
   Brock.

 

Re:Setting OnMouseMove Event at Runtime


If I understand you correctly all you have to do is define a method (procedure) in your form exactly like the OnMouseMove procedure and then assign it
to the Image.

type
    TMyForm = class(Form)
       .
       .
       .
      procedure WhatIWantToDo(Sender: TObject; Shift: TShiftState; X, Y: Integer);
     end;

// then out in codeland somewhere....

begin
  MyImagePlace.OnMouseMove := WhatIWantToDo;
end;

As for your second question... Make sure that you check the class first but you can do this...

procedure Form1.Example(Sender: TObject);
begin
  if Sender is TEdit then
     TEdit(Sender).Left := 250;
end;

Quote
Brock Logan wrote:
> I have declared an array of TImage controls.  I need to be able to
> assign code to it's onMouseMove Event.  I have tried everything I know
> to get this to work, but I do not know how to pass the event the
> TShiftState parameter.

> Also is there anyway of referencing a control by using :

> procedure Form1.Example(Sender: TObject);
> begin
>    Sender.Left := 250;
> end;

> If anybody could help me with these problems, it would be greatly
> appreciated.

> Regards,
>    Brock.

Other Threads