The
OnMouseMove event first appears in the
TControl class, in a protected section (
TCustomControl and
TControl). Therefore, it's not accessible outside the class. Only descendants of this class (i.e.,
TControl) have access. The descendant is the
TWinControl class, but it does not make this event public. The descendant of
TWinControl is the
TCustomControl class, which also does not expose this event. So, in the
TCustomControl class, the
OnMouseMove event is still in a protected section. So you need to create a class derived from
TCustomControl, e.g.
TMyOwnCustomControl, and in this derived class you need to add code that exposes the
OnMouseMove event. You would have to do the same for any event that isn't public or published.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
type
{TMyVeryOwnControl}
TMyVeryOwnControl = class(TCustomCOntrol)
published
property OnMouseMove;
end;
{TForm1}
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
public
MyControl: TMyVeryOwnControl;
procedure MyControlOnMouseMove(Sender: TObject; Shift: TShiftState; X: Integer; Y: Integer);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{TForm1}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyControl := TMyVeryOwnControl.Create(Form1);
MyControl.Parent := Form1;
MyControl.Name := 'MyControl';
MyControl.Width := 200;
MyControl.Height := 150;
MyControl.Left := 100;
MyControl.Top := 50;
MyControl.Color := clLime;
MyControl.BorderStyle := bsSingle;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MyControl.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MyControl.OnMouseMove := @MyControlOnMouseMove;
end;
procedure TForm1.MyControlOnMouseMove(Sender: TObject; Shift: TShiftState;
X: Integer; Y: Integer);
begin
Label1.Caption := (Sender as TCustomControl).Name + ', X: ' + X.ToString +
', Y: ' + Y.ToString + ', "MyControlOnMouseMove" fired!';
end;
end.
I am attaching a sample project (below as an attachment).