• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Component Event Problem

I wrote a component from the TGraphicControl class
like that : TmyComponent = class(TgraphicControl), etc.

The problem is that I want to add onMouseDown and onMouseUp events. I succeed to make them appear in the object inspector but they don't execute at runTime.
( I try to add them in the property section, but nothing happens. I also tried to declare 2 procedures and within them "inherited OnMouseDown(..)" -> nothing more).

How Can I do?
0
logosapience
Asked:
logosapience
  • 4
  • 3
1 Solution
 
simonetCommented:
Can you post some code? (Only the important class definitions for the component and the 2 procedures).

Alex
0
 
logosapienceAuthor Commented:
Here's some code :

TMyComponent : Class(TGraphicControl)
Private
...

Protected
 procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer); override;
 procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer); override;
...

Published
  property OnMouseDown;
  property OnMouseUp;
...

procedure TSpeedButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
begin
  inherited MouseDown(Button, Shift, X, Y);
end;
   
procedure TSpeedButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
begin
  inherited MouseUp(Button, Shift, X, Y);
end;

0
 
kotikCommented:
Hi!
You have to declare procedural types for your events something like this:

TMouseDownEvent = procedure(Sender: TObject; X, Y: integer; Shift: TShiftState);

in your class definition:

private
FonMouseDown: TMouseDownEvent;
...
published
OnMouseDown: TMouseDownEvent read FonMouseDown write FonMouseDown;

and then add a handler of WM_LBUTTONDOWN and WM_RBUTTONDOWN event.
and in the handler add this code:

if Assigned(FonMouseDown) then FounMouseDown(Sender, X, Y, Shift);

You can find samples of such things in VCL sources.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kotikCommented:
Hi!
You have to declare procedural types for your events something like this:

TMouseDownEvent = procedure(Sender: TObject; X, Y: integer; Shift: TShiftState);

in your class definition:

private
FonMouseDown: TMouseDownEvent;
...
published
OnMouseDown: TMouseDownEvent read FonMouseDown write FonMouseDown;

and then add a handler of WM_LBUTTONDOWN and WM_RBUTTONDOWN event.
and in the handler add this code:

if Assigned(FonMouseDown) then FounMouseDown(Sender, X, Y, Shift);

You can find samples of such things in VCL sources.
0
 
kotikCommented:
O-o-o-ps!
Ingnore what I said before.
You only have to add this and nothing more:

published
...
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
...
end;

Look at TImage source code in ExtCtrls.pas
0
 
logosapienceAuthor Commented:
I already tried this but nothing happens!
0
 
logosapienceAuthor Commented:
Kotik : Re-post an answer, your first comment was right (with messages)... It works very well

Thanks very much for quick and right answer...

Logos.
0
 
kotikCommented:
OK, logosapience!
Maybe I didn't understand your question, but I'm glad that my answer helped you :)
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.

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