Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Component Event Problem

Posted on 1999-07-23
8
Medium Priority
?
203 Views
Last Modified: 2010-04-04
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
Comment
Question by:logosapience
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 1390687
Can you post some code? (Only the important class definitions for the component and the 2 procedures).

Alex
0
 
LVL 1

Author Comment

by:logosapience
ID: 1390688
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
 
LVL 2

Expert Comment

by:kotik
ID: 1390689
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:kotik
ID: 1390690
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
 
LVL 2

Expert Comment

by:kotik
ID: 1390691
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
 
LVL 1

Author Comment

by:logosapience
ID: 1390692
I already tried this but nothing happens!
0
 
LVL 1

Author Comment

by:logosapience
ID: 1390693
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
 
LVL 2

Accepted Solution

by:
kotik earned 200 total points
ID: 1390694
OK, logosapience!
Maybe I didn't understand your question, but I'm glad that my answer helped you :)
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

722 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