This is an example of the 'framework' code generated from simply choosing 'file|new' and choosing, from a tree view, the selection 'visual component|can receive focus|TComponent'... all mouse clicks. It basically uses inheritance to build a template for you.
It is a sort of 'Case Tool' for components/classes.
{ ****************************************************************** }
{ }
{ VCL component TMyClass }
{ }
{ Code generated by Component Create for Delphi }
{ }
{ Generated from untitled component definition }
{ on 26 March 2012 at 20:44 }
{ }
{ Copyright © 2012 by ... }
{ }
{ ****************************************************************** }
unit MyUnit;
interface
uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
Forms, Graphics;
type
TMyClass = class(TCustomControl)
private
{ Private fields of TMyClass }
{ Private methods of TMyClass }
{ Method to set variable and property values and create objects }
procedure AutoInitialize;
{ Method to free any objects created by AutoInitialize }
procedure AutoDestroy;
protected
{ Protected fields of TMyClass }
{ Protected methods of TMyClass }
procedure Click; override;
procedure KeyPress(var Key : Char); override;
procedure Loaded; override;
procedure Paint; override;
public
{ Public fields and properties of TMyClass }
{ Public methods of TMyClass }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published properties of TMyClass }
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
procedure Register;
implementation
procedure Register;
begin
{ Register TMyClass with Samples as its
default page on the Delphi component palette }
RegisterComponents('Samples', [TMyClass]);
end;
{ Method to set variable and property values and create objects }
procedure TMyClass.AutoInitialize;
begin
end; { of AutoInitialize }
{ Method to free any objects created by AutoInitialize }
procedure TMyClass.AutoDestroy;
begin
{ No objects from AutoInitialize to free }
end; { of AutoDestroy }
{ Override OnClick handler from TCustomControl }
procedure TMyClass.Click;
begin
{ Call method of parent class }
inherited Click;
end;
{ Override OnKeyPress handler from TCustomControl }
procedure TMyClass.KeyPress(var Key : Char);
begin
{ Call method of parent class }
inherited KeyPress(Key);
end;
constructor TMyClass.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
AutoInitialize;
{ Code to perform other tasks when the component is created }
end;
destructor TMyClass.Destroy;
begin
AutoDestroy;
inherited Destroy;
end;
procedure TMyClass.Loaded;
begin
inherited Loaded;
{ Perform any component setup that depends on the property
values having been set }
end;
procedure TMyClass.Paint;
begin
{ Draw the component using the methods supplied by its Canvas
property (of type TCanvas). For example: }
Canvas.Brush.Color := clGreen;
Canvas.Rectangle(0, 0, Width, Height);
end;
end.