SlideShare une entreprise Scribd logo
1  sur  12
SuperComponents
How to Build Aggregate/Composite Components in Delphi™
Copyright © 1996, 1997 Mark Miller
Eagle Software
What are SuperComponents?
SuperComponents, also known as aggregate or compound components, are collections of existing subcomponents and their relationships combined into a single component. The collections are typically
arranged inside a container parent component that manages the visual layout of the sub-components.

Advantages
SuperComponents take all of the advantages of normal components and build on them. Rapid application
development, object reuse, and user interface consistency are all benefits. Code shrinkage is another. If
you have two or more forms containing similar component relationships (either inside an application or
among several), that component relationship is tied to each form with - you guessed it - code. That
binding Object Pascal code is duplicated with each form the component group lies on. By fusing the
component collections into a single component, the code to manage the sub-component relationships
disappears from the user interface code. The code for each form more truly represents its functionality; it's
easier to read and maintain.
Another benefit achieved through the use of SuperComponents is multiple form inheritance. You can take
parts of different forms (SuperComponents) and group them together into a new form. This leads to even
faster prototyping and user interface design than normally experienced with Delphi.
SuperComponents can simplify the properties needed to control the collection. Instead of dealing with
properties and events for each component in the collection, the SuperComponent only exposes the
properties and events it needs, thereby reducing the design-time complexity of the component.
As mentioned earlier, SuperComponents can embody the rules of the relationship among the
subcomponents. This relationship might represent an algorithm or solution to a problem, or it might
support state changes not present in any of the individual parts. Algorithm parameters and/or hooks to
state changes can be easily exposed through new properties and events.
Finally, SuperComponents can be thought of as mini-apps. They are components themselves, and as such,
lend themselves to a well-defined segregation from the rest of the project they are contained in. In team
development environments, this means that developers most familiar with the problem and solution
(whatever they be) can design the SuperComponents so that less-experienced developers can piece
together the application with these building blocks.
Disadvantages
There are two disadvantages to making SuperComponents. First, visual SuperComponents require an
additional Windows handle. Second, there is a small amount of overhead in the container parent
component that holds all the sub-components.

Before We Start
It is useful to distinguish among the different roles developers and users take when dealing with
components. There are three that we are concerned with:
•Application Users (a.k.a. "users") will use applications built with the components we make.
•Application Developers (a.k.a. "developers") will build applications using our components.
•Component Writers (that's us!) will create components that will make is easier for developers to build
applications and easier for users to use. It's important to note that as a component writer, you're designing
for two customers.

Visual Containment
The steps to building a SuperComponent are roughly as follows:
1.
2.
3.
4.
5.
6.

Design the layout of your components inside a form in Delphi, placing all the components inside a
TPanel (or a descendant thereof).
Select and copy the panel and paste it into a text file.
Replace all instances of " = " with " := ", and add a semi-colon to the end of each line.
Convert all DFM "object" declaration lines to appropriate object constructor code, setting the parent
of all visual controls to the container panel.
Clean up any remaining code. Bitmaps will need to be placed in resource files.
Place this new pascal code inside a create constructor for your component. Within the constructor ,
group object sections under the appropriate sub-component creator.

Let's use an example to illustrate these steps. We'll make an OK/Cancel/Help button combination. Inside
Delphi, the layout looks like this (Note: the TPanel's border is set to none):

Selecting, copying and pasting the above collection into a text file yields the following:
object Panel1: TPanel
Left = 114
Top = 10
Width = 75
Height = 95
BevelOuter = bvNone
TabOrder = 0
object OKButton: TButton
Left = 0
Top = 0
Width = 75
Height = 25
Caption = 'OK'
Default = True
ModalResult = 1
TabOrder = 0
end
object CancelButton: TButton
Left = 0
Top = 35
Width = 75
Height = 25
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 1
end
object HelpButton: TButton
Left = 0
Top = 70
Width = 75
Height = 25
Caption = 'Help'
TabOrder = 2
end
end
This is the text representation of our SuperComponent group. Next, we need to convert this text to
something that looks a little more like Object Pascal:
object Panel1: TPanel
Left := 114;
Top := 10;
Width := 75;
Height := 95;
BevelOuter := bvNone;
TabOrder := 0;
object OKButton: TButton
Left := 0;
Top := 0;
Width := 75;
Height := 25;
Caption := 'OK';
Default := True;
ModalResult := 1;
TabOrder := 0;
end
object CancelButton: TButton
Left := 0;
Top := 35;
Width := 75;
Height := 25;
Cancel := True;
Caption := 'Cancel';
ModalResult := 2;
TabOrder := 1;
end
object HelpButton: TButton
Left := 0;
Top := 70;
Width := 75;
Height := 25;
Caption := 'Help';
TabOrder := 2;
end
end
Now we're getting closer to what we want. The next step is to transfer the panel initialization to the
component's constructor. We'll create the embedded controls here, too:
constructor TOkCancelHelp.Create(AOwner: TComponent);
{ Creates an object of type TOkCancelHelp, and initializes properties. }
begin
inherited Create(AOwner);
Width := 75;
Height := 95;
BevelOuter := bvNone;
TabOrder := 0;
OKButton := TButton.Create(Self);
OKButton.Parent := Self;
CancelButton := TButton.Create(Self);
CancelButton.Parent := Self;
HelpButton := TButton.Create(Self);
HelpButton.Parent := Self;
end; { Create }
The three buttons, OKButton, CancelButton, and HelpButton need to be declared as fields of our new
component. Our component's declaration looks like this:
type
TOkCancelHelp = class(TPanel)
OKButton: TButton;
CancelButton: TButton;
HelpButton: TButton;
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published properties and events }
end; { TOkCancelHelp }
Now let's take that converted DFM text and initialize the three buttons. Although you can do this inside
our component's constructor, some VCL sub-component initialization code depends on a windows handle
existing in its parent. At the time when our new SuperComponent is created (inside the Create
constructor), this handle does not yet exist. So we need to find a method we can override in the TPanel
that is called before the component is displayed and before its loaded method is called, but after a
windows handle is assigned to the TPanel. The CreateWindowHandle method is the best place to do this.
An override of this method, with the DFM initialization code inserted, looks like this:
procedure TOkCancelHelp.CreateWindowHandle(const Params: TCreateParams);
{ Calls inherited CreateWindowHandle and initializes subcomponents. }
begin
inherited CreateWindowHandle(Params);
with OKButton do
begin
Left := 0;
Top := 0;
Width := 75;
Height := 25;
Caption := 'OK';
Default := True;
ModalResult := 1;
TabOrder := 0;
end; { OKButton }
with CancelButton do
begin
Left := 0;
Top := 35;
Width := 75;
Height := 25;
Cancel := True;
Caption := 'Cancel';
ModalResult := 2;
TabOrder := 1;
end; { CancelButton }
with HelpButton do
begin
Left := 0;
Top := 70;
Width := 75;
Height := 25;
Caption := 'Help';
TabOrder := 2;
end; { HelpButton }
end; { CreateWindowHandle }
And the component declaration now looks like this:
type
TOkCancelHelp = class(TPanel)
OKButton: TButton;
CancelButton: TButton;
HelpButton: TButton;
private
{ Private declarations }
protected
{ Protected declarations }
procedure CreateWindowHandle(const Params: TCreateParams); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published properties and events }
end; { TOkCancelHelp }
Finally, we need to add a register method so we can place our new component onto Delphi's component
palette:
procedure Register;
begin
RegisterComponents('CDK', [TOkCancelHelp]);
end; { Register }

Exposing Sub-Component Properties
Grouping components together to create new SuperComponents is a pretty neat trick. One advantage is
that it allows you to isolate many of the grouped components' properties from application developers. In
fact unless you explicitly state otherwise, all of the grouped components properties will be hidden from
developers!
So how do you expose a sub-component property? You need to create two transfer methods that transfer
the sub-component's properties to the outside world.
For example, in our TOkCancelHelp component, it might be useful to expose the caption property so
application writers can change it (e.g., for application development in a language other than English).
Our transfer methods look a lot like the standard property Get and Set methods we're already familiar
with. Here's the declaration for the OK button's caption property:
type
TOkCancelHelp = class(TPanel)
.
.
.
private
{ Private declarations }
procedure SetCaption_OKButton(newValue: TCaption);
function GetCaption_OKButton: TCaption;
.
.
.
published
{ Published properties and events }
property Caption_OKButton: TCaption read GetCaption_OKButton write
SetCaption_OKButton;
end;
These transfer methods pass the property values to and from the subcomponents. Their implementation
looks like this:
function TOkCancelHelp.GetCaption_OKButton: TCaption;
{ Returns the Caption property from the OKButton subcomponent. }
begin
result := OKButton.Caption;
end; { GetCaption_OKButton }
procedure TOkCancelHelp.SetCaption_OKButton(newValue: boolean);
{ Sets the OKButton subcomponent's Caption property to newValue. }
begin
OKButton.Caption := newValue;
end; { SetCaption_OKButton }
You may notice that there is no field variable for this property. All sub-component properties rely on the
sub-components themselves for storage. Also notice that unlike most Set methods, this one doesn't check
to see if the internal value is different from the passed-in newValue. We let the sub-component handle this
check if necessary.

Exposing Sub-Component Events
Just as you would need to expose a sub-component's properties, you might also need to expose its events.
The theory behind exposing sub-component events is similar to that used to expose properties. The
difference is that with events, we need to store the event handler in a field variable (just like we would for
a normal event). Additionally we have to hook in to any sub-componenent event that we want to make
available to our component users, which means creating our own event handler for it. Event handlers
must be assigned dynamically when the component is first created. The declaration for an exposed event
and the event handler that surfaces it looks like this:
type
TOkCancelHelp = class(TPanel)
.
.
.
private
{ Private declarations }
FOnClick_OKButton: TNotifyEvent;
.
.
.
procedure Click_OKButtonTransfer(Sender: TObject);
published
{ Published properties and events }
.

{ TNotifyEvent }
.
.
property OnClick_OKButton: TNotifyEvent read FOnClick_OKButton
write FOnClick_OKButton;
end;
Here, Click_OKButtonTransfer acts as the event handler. Notice that its type, TNotifyEvent, matches the
expected type for the OnClick event (TNotifyEvent). The implementation for the transfer method looks
like this:
procedure TOkCancelHelp.Click_OKButtonTransfer(Sender: TObject);
{ Transfers the OKButton OnClick event to the outside world. }
begin
if assigned(FOnClick_OKButton) then
FOnClick_OKButton(Self); { Substitute Self for subcomponent's
Sender. }
end; { Click_OKButtonTransfer }

If you've triggered events before, you probably recognize this code. The if-clause checks to see if the event
is assigned (typically performed via the Object Inspector at design-time), and if so calls it, passing a
reference to itself (the SuperComponent) to the component user's event handler. So, the sub-component's
event is handled by our transfer method, which in turn passes the event to a component user's event
handler (that's right -- two event handlers for each event!). To hook up this chain of events, all we do is
dynamically assign the event transfer method to the sub-component's event. We do this in the overridden
CreateWindowHandle method:
procedure TOkCancelHelp.CreateWindowHandle(const Params: TCreateParams);
{ Calls inherited CreateWindowHandle and initializes subcomponents. }
begin
inherited CreateWindowHandle(Params);
with OKButton do
begin
.
.
.
OnClick := Click_OKButtonTransfer;
end; { OKButton }
.
.
.
end; { CreateWindowHandle }

Hooking in to Sub-Component Events
Sometimes you want to respond to a sub-component event without exposing it. The steps involved here are
similar to those you'd follow to expose a sub-component event, except you don't declare the event (and you
don't need the corresponding event field variable).
type
TOkCancelHelp = class(TPanel)
.
.
.
private
{ Private declarations }
.
.
.
procedure Click_CancelButtonHandler(Sender: TObject);
{ TNotifyEvent }
published
.
.
.
end;
The handler looks like this:
procedure TOkCancelHelp.Click_CancelButtonHandler(Sender: TObject);
{ Handles the CancelButton OnClick event. }
begin
{ Place your event-handling code here. }
end; { Click_CancelButtonHandler }
We glue it all together by dynamically assigning our handler to the sub-component event, just as we do
when we want to expose a sub-component event:
procedure TOkCancelHelp.CreateWindowHandle(const Params: TCreateParams);
{ Calls inherited CreateWindowHandle and initializes subcomponents. }
begin
inherited CreateWindowHandle(Params);
.
.
.
with CancelButton do
begin
.
.
.
OnClick := Click_CancelButtonHandler;
end; { CancelButton }
.
.
.
end; { CreateWindowHandle }

Summary
SuperComponents promote consistency and reuse. They can embody commonly-used configurations of
controls, dramatically cutting development time and slashing code size. And the techniques involved here
are not difficult to master.
Recommended Reading
The following books were current at the time of this writing. Make sure you check for the most recent
edition.
Developing Custom Delphi Components
by Ray Konopka; edited by Jeff Duntemann
Coriolis Group Books
(800) 410-0192 or (602) 483-0192
http://www.coriolis.com
585 pages
ISBN 1-883577-47-0
This book is highly recommended if you need additional information on component building or building
business components. It is filled with useful information and excellent examples. The explanations are
clear and easy to understand. In addition, Ray Konopka’s TRzBusinessComponent, included with the
CDK, is presented and detailed in his book.

Secrets of Delphi 2 -- Exposing Undocumented Features of Delphi
by Ray Lischner
Waite Group Press
831 pages
ISBN 1-57169-026-3
This is an amazing book, packed with valuable information you can’t get anywhere else. Also contains
excellent coverage of property editors, component editors, and other advanced component-building topics.

The Delphi Magazine
Edited by Chris J G Frizelle
iTec Publishing
To subscribe in the UK:
Tel/Fax: +44 (0) 181 460 0650
Email: 70630.717@compuserve.com
To subscribe in the US:
Phone: (802) 244-7820
Email: 70602.1215@compuserve.com
This magazine consistently contains excellent technical articles on Delphi-related subjects. Also contains
a monthly column by Bob Swart (a.k.a. Dr. Bob) on component building in Delphi.
Design Patterns--Elements of Reusable Object-Oriented Software
by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
Foreword by Grady Booch
Addison-Wesley Publishing Company
395 pages
ISBN 0-201-63361-2
This book organizes and presents a catalog of proven object-oriented solutions for architecting complex
systems that you can apply to your own specific applications. These design constructs are labeled,
allowing your development team to share a common vocabulary. The CDK help file references two of the
design patterns in this book: the Proxy pattern and the Template Method pattern. The examples are in
C++, but the patterns apply to all programming languages.

Component Writer’s Guide
by Borland International, Inc.
(408) 431-1000
156 pages
The Component Writers Guide is a lean but important resource for learning about how to create working
components and to ensure that components you write are well-behaved parts of the Delphi environment.
The book guides you to writing components that fit in well with any Delphi application.

About the Author
Mark Miller is the lead software engineer at Eagle Software. Mark holds the primary vision for the
Component Developer Kit for Delphi (the CDK) reAct, a component testing tool for Delphi, as well as
several other Delphi add-ons currently in development. He has been programming in Pascal, Object
Pascal, and Delphi for nearly 16 years.
He can be reached at markm@eagle-software.com, or via CompuServe at 76043,2422.

Contenu connexe

Tendances

Scaleform Mini-Games Tutorial 3/3
Scaleform Mini-Games Tutorial 3/3Scaleform Mini-Games Tutorial 3/3
Scaleform Mini-Games Tutorial 3/3Reese Mills
 
Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed contentYogesh Kumar
 
Scaleform Mini-Games Tutorial 1/3
Scaleform Mini-Games Tutorial 1/3Scaleform Mini-Games Tutorial 1/3
Scaleform Mini-Games Tutorial 1/3Reese Mills
 
Scaleform Mini-Games Tutorial 2/3
Scaleform Mini-Games Tutorial 2/3Scaleform Mini-Games Tutorial 2/3
Scaleform Mini-Games Tutorial 2/3Reese Mills
 
VB.Net-Controls and events
VB.Net-Controls and eventsVB.Net-Controls and events
VB.Net-Controls and eventsPrachi Sasankar
 
MVC and Other Design Patterns
MVC and Other Design PatternsMVC and Other Design Patterns
MVC and Other Design PatternsJonathan Simon
 
Java Swing Custom GUI MVC Component Tutorial
Java Swing Custom GUI MVC Component TutorialJava Swing Custom GUI MVC Component Tutorial
Java Swing Custom GUI MVC Component TutorialSagun Dhakhwa
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solutionMazenetsolution
 
Programming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash MovieProgramming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash MovieMahmoud Samir Fayed
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 
Programming Without Coding Technology (PWCT) - ActiveSkin ActiveX Control
Programming Without Coding Technology (PWCT) - ActiveSkin ActiveX ControlProgramming Without Coding Technology (PWCT) - ActiveSkin ActiveX Control
Programming Without Coding Technology (PWCT) - ActiveSkin ActiveX ControlMahmoud Samir Fayed
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Mahmoud Samir Fayed
 

Tendances (20)

Scaleform Mini-Games Tutorial 3/3
Scaleform Mini-Games Tutorial 3/3Scaleform Mini-Games Tutorial 3/3
Scaleform Mini-Games Tutorial 3/3
 
Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed content
 
Scaleform Mini-Games Tutorial 1/3
Scaleform Mini-Games Tutorial 1/3Scaleform Mini-Games Tutorial 1/3
Scaleform Mini-Games Tutorial 1/3
 
Scaleform Mini-Games Tutorial 2/3
Scaleform Mini-Games Tutorial 2/3Scaleform Mini-Games Tutorial 2/3
Scaleform Mini-Games Tutorial 2/3
 
VB.Net-Controls and events
VB.Net-Controls and eventsVB.Net-Controls and events
VB.Net-Controls and events
 
MVC and Other Design Patterns
MVC and Other Design PatternsMVC and Other Design Patterns
MVC and Other Design Patterns
 
09events
09events09events
09events
 
Java Swing Custom GUI MVC Component Tutorial
Java Swing Custom GUI MVC Component TutorialJava Swing Custom GUI MVC Component Tutorial
Java Swing Custom GUI MVC Component Tutorial
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Matlab GUI
Matlab GUIMatlab GUI
Matlab GUI
 
Swing
SwingSwing
Swing
 
Programming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash MovieProgramming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash Movie
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Test
TestTest
Test
 
Event handling in Java(part 2)
Event handling in Java(part 2)Event handling in Java(part 2)
Event handling in Java(part 2)
 
Programming Without Coding Technology (PWCT) - ActiveSkin ActiveX Control
Programming Without Coding Technology (PWCT) - ActiveSkin ActiveX ControlProgramming Without Coding Technology (PWCT) - ActiveSkin ActiveX Control
Programming Without Coding Technology (PWCT) - ActiveSkin ActiveX Control
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
 
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10
 

En vedette

Bangla booklet on safe road use
Bangla booklet on safe road useBangla booklet on safe road use
Bangla booklet on safe road usePolicy Adda
 
Presentación Marca Eres Tú de Eva Collado Durán en Asturias
Presentación Marca Eres Tú de Eva Collado Durán en AsturiasPresentación Marca Eres Tú de Eva Collado Durán en Asturias
Presentación Marca Eres Tú de Eva Collado Durán en AsturiasElena_Arnaiz
 
Proposta de pauta conjunta asma al·lèrgica pediàtrica
Proposta de pauta conjunta asma al·lèrgica pediàtricaProposta de pauta conjunta asma al·lèrgica pediàtrica
Proposta de pauta conjunta asma al·lèrgica pediàtricaPediatriadeponent
 
Digital Dealer Magazine - June 2009
Digital Dealer Magazine - June 2009Digital Dealer Magazine - June 2009
Digital Dealer Magazine - June 2009Ralph Paglia
 
Diagramadelpolvo
DiagramadelpolvoDiagramadelpolvo
Diagramadelpolvoguest957901
 
Hoja de vida
Hoja de vidaHoja de vida
Hoja de vidarentersa
 
Des maisons de prestige
Des maisons de prestigeDes maisons de prestige
Des maisons de prestigeÉric NIAKISSA
 
Reading: Review on vehicle detection based on video for Traffic Surveillance
Reading: Review on vehicle detection based on video for Traffic SurveillanceReading: Review on vehicle detection based on video for Traffic Surveillance
Reading: Review on vehicle detection based on video for Traffic SurveillanceLuqman Abdul Mushawwir
 
Bruce sterling la caza de hackers - shimeria
Bruce sterling   la caza de hackers - shimeriaBruce sterling   la caza de hackers - shimeria
Bruce sterling la caza de hackers - shimeriajose guillen
 
Museo Thyssen Málaga
Museo Thyssen MálagaMuseo Thyssen Málaga
Museo Thyssen Málagavirginiayosoy
 
Altas octubre 2012
Altas octubre 2012Altas octubre 2012
Altas octubre 2012Dominios.es
 
Boat docking system
Boat docking systemBoat docking system
Boat docking systemdockmate
 

En vedette (20)

Bangla booklet on safe road use
Bangla booklet on safe road useBangla booklet on safe road use
Bangla booklet on safe road use
 
Presentación Marca Eres Tú de Eva Collado Durán en Asturias
Presentación Marca Eres Tú de Eva Collado Durán en AsturiasPresentación Marca Eres Tú de Eva Collado Durán en Asturias
Presentación Marca Eres Tú de Eva Collado Durán en Asturias
 
Proposta de pauta conjunta asma al·lèrgica pediàtrica
Proposta de pauta conjunta asma al·lèrgica pediàtricaProposta de pauta conjunta asma al·lèrgica pediàtrica
Proposta de pauta conjunta asma al·lèrgica pediàtrica
 
Digital Dealer Magazine - June 2009
Digital Dealer Magazine - June 2009Digital Dealer Magazine - June 2009
Digital Dealer Magazine - June 2009
 
1 Botella 1 Mensaje
1 Botella 1 Mensaje1 Botella 1 Mensaje
1 Botella 1 Mensaje
 
Diagramadelpolvo
DiagramadelpolvoDiagramadelpolvo
Diagramadelpolvo
 
Hoja de vida
Hoja de vidaHoja de vida
Hoja de vida
 
Des maisons de prestige
Des maisons de prestigeDes maisons de prestige
Des maisons de prestige
 
Tríptico comercial 2
Tríptico comercial 2Tríptico comercial 2
Tríptico comercial 2
 
106. hucurat suresi
106. hucurat suresi106. hucurat suresi
106. hucurat suresi
 
Reading: Review on vehicle detection based on video for Traffic Surveillance
Reading: Review on vehicle detection based on video for Traffic SurveillanceReading: Review on vehicle detection based on video for Traffic Surveillance
Reading: Review on vehicle detection based on video for Traffic Surveillance
 
Bruce sterling la caza de hackers - shimeria
Bruce sterling   la caza de hackers - shimeriaBruce sterling   la caza de hackers - shimeria
Bruce sterling la caza de hackers - shimeria
 
Museo Thyssen Málaga
Museo Thyssen MálagaMuseo Thyssen Málaga
Museo Thyssen Málaga
 
Altas octubre 2012
Altas octubre 2012Altas octubre 2012
Altas octubre 2012
 
Rail services may_2010lr
Rail services may_2010lrRail services may_2010lr
Rail services may_2010lr
 
La Tecnología de Microarrays en Medicina Reproductiva. José A.Horcajadas
La Tecnología de Microarrays en Medicina Reproductiva. José A.HorcajadasLa Tecnología de Microarrays en Medicina Reproductiva. José A.Horcajadas
La Tecnología de Microarrays en Medicina Reproductiva. José A.Horcajadas
 
Exposición
ExposiciónExposición
Exposición
 
INDUC-SHRAN
INDUC-SHRANINDUC-SHRAN
INDUC-SHRAN
 
Indicadores de gestión
Indicadores de gestión Indicadores de gestión
Indicadores de gestión
 
Boat docking system
Boat docking systemBoat docking system
Boat docking system
 

Similaire à Super components en Pascal

Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesDavid Voyles
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfKaty Slemon
 
Streamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxStreamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxShubhamJayswal6
 
Google calendar integration in iOS app
Google calendar integration in iOS appGoogle calendar integration in iOS app
Google calendar integration in iOS appKetan Raval
 
maXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO StandardmaXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO StandardMax Kleiner
 
How to Detect a Click Outside a React Component.pptx
How to Detect a Click Outside a React Component.pptxHow to Detect a Click Outside a React Component.pptx
How to Detect a Click Outside a React Component.pptxBOSC Tech Labs
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5Akhil Mittal
 
The visual studio start page is shown in the figure below
The visual studio start page is shown in the figure belowThe visual studio start page is shown in the figure below
The visual studio start page is shown in the figure belowTan Ps
 
EclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial ExercisesEclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial ExercisesEric Cloninger
 
Keynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxKeynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxEqraKhattak
 
2007 Max Presentation - Creating Custom Flex Components
2007 Max Presentation - Creating Custom Flex Components2007 Max Presentation - Creating Custom Flex Components
2007 Max Presentation - Creating Custom Flex Componentsmichael.labriola
 

Similaire à Super components en Pascal (20)

Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile services
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
Visual Basic.pptx
Visual Basic.pptxVisual Basic.pptx
Visual Basic.pptx
 
Visual basic
Visual basicVisual basic
Visual basic
 
Tutorials2
Tutorials2Tutorials2
Tutorials2
 
Tutorials3
Tutorials3Tutorials3
Tutorials3
 
Tutorials v10
Tutorials v10Tutorials v10
Tutorials v10
 
Streamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxStreamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptx
 
Google calendar integration in iOS app
Google calendar integration in iOS appGoogle calendar integration in iOS app
Google calendar integration in iOS app
 
maXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO StandardmaXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO Standard
 
How to Detect a Click Outside a React Component.pptx
How to Detect a Click Outside a React Component.pptxHow to Detect a Click Outside a React Component.pptx
How to Detect a Click Outside a React Component.pptx
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5
 
6. Compile And Run
6. Compile And Run6. Compile And Run
6. Compile And Run
 
The visual studio start page is shown in the figure below
The visual studio start page is shown in the figure belowThe visual studio start page is shown in the figure below
The visual studio start page is shown in the figure below
 
EclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial ExercisesEclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial Exercises
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Keynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxKeynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptx
 
2007 Max Presentation - Creating Custom Flex Components
2007 Max Presentation - Creating Custom Flex Components2007 Max Presentation - Creating Custom Flex Components
2007 Max Presentation - Creating Custom Flex Components
 

Plus de Paco Miró

Cqi 11 plating system assessment process table b - surface conditioning of me...
Cqi 11 plating system assessment process table b - surface conditioning of me...Cqi 11 plating system assessment process table b - surface conditioning of me...
Cqi 11 plating system assessment process table b - surface conditioning of me...Paco Miró
 
Cqi 11 plating system assessment process table a - zinc - zinc alloy plating
Cqi 11 plating system assessment process table a - zinc - zinc alloy platingCqi 11 plating system assessment process table a - zinc - zinc alloy plating
Cqi 11 plating system assessment process table a - zinc - zinc alloy platingPaco Miró
 
Cqi 11 plating system assessment section 5 - job audit - finished product review
Cqi 11 plating system assessment section 5 - job audit - finished product reviewCqi 11 plating system assessment section 5 - job audit - finished product review
Cqi 11 plating system assessment section 5 - job audit - finished product reviewPaco Miró
 
Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...
Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...
Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...Paco Miró
 
Cqi 11 plating system assessment section 3 - zinc alloy plating equipment
Cqi 11 plating system assessment section 3 -  zinc alloy plating equipmentCqi 11 plating system assessment section 3 -  zinc alloy plating equipment
Cqi 11 plating system assessment section 3 - zinc alloy plating equipmentPaco Miró
 
cqi 11 plating system assessment - Portada
cqi 11 plating system assessment - Portadacqi 11 plating system assessment - Portada
cqi 11 plating system assessment - PortadaPaco Miró
 
cqi 11 plating system assessment
cqi 11 plating system assessmentcqi 11 plating system assessment
cqi 11 plating system assessmentPaco Miró
 

Plus de Paco Miró (7)

Cqi 11 plating system assessment process table b - surface conditioning of me...
Cqi 11 plating system assessment process table b - surface conditioning of me...Cqi 11 plating system assessment process table b - surface conditioning of me...
Cqi 11 plating system assessment process table b - surface conditioning of me...
 
Cqi 11 plating system assessment process table a - zinc - zinc alloy plating
Cqi 11 plating system assessment process table a - zinc - zinc alloy platingCqi 11 plating system assessment process table a - zinc - zinc alloy plating
Cqi 11 plating system assessment process table a - zinc - zinc alloy plating
 
Cqi 11 plating system assessment section 5 - job audit - finished product review
Cqi 11 plating system assessment section 5 - job audit - finished product reviewCqi 11 plating system assessment section 5 - job audit - finished product review
Cqi 11 plating system assessment section 5 - job audit - finished product review
 
Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...
Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...
Cqi 11 plating system assessment section 4 - decorative (cu, ni, cr) plating ...
 
Cqi 11 plating system assessment section 3 - zinc alloy plating equipment
Cqi 11 plating system assessment section 3 -  zinc alloy plating equipmentCqi 11 plating system assessment section 3 -  zinc alloy plating equipment
Cqi 11 plating system assessment section 3 - zinc alloy plating equipment
 
cqi 11 plating system assessment - Portada
cqi 11 plating system assessment - Portadacqi 11 plating system assessment - Portada
cqi 11 plating system assessment - Portada
 
cqi 11 plating system assessment
cqi 11 plating system assessmentcqi 11 plating system assessment
cqi 11 plating system assessment
 

Dernier

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Dernier (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Super components en Pascal

  • 1. SuperComponents How to Build Aggregate/Composite Components in Delphi™ Copyright © 1996, 1997 Mark Miller Eagle Software What are SuperComponents? SuperComponents, also known as aggregate or compound components, are collections of existing subcomponents and their relationships combined into a single component. The collections are typically arranged inside a container parent component that manages the visual layout of the sub-components. Advantages SuperComponents take all of the advantages of normal components and build on them. Rapid application development, object reuse, and user interface consistency are all benefits. Code shrinkage is another. If you have two or more forms containing similar component relationships (either inside an application or among several), that component relationship is tied to each form with - you guessed it - code. That binding Object Pascal code is duplicated with each form the component group lies on. By fusing the component collections into a single component, the code to manage the sub-component relationships disappears from the user interface code. The code for each form more truly represents its functionality; it's easier to read and maintain. Another benefit achieved through the use of SuperComponents is multiple form inheritance. You can take parts of different forms (SuperComponents) and group them together into a new form. This leads to even faster prototyping and user interface design than normally experienced with Delphi. SuperComponents can simplify the properties needed to control the collection. Instead of dealing with properties and events for each component in the collection, the SuperComponent only exposes the properties and events it needs, thereby reducing the design-time complexity of the component. As mentioned earlier, SuperComponents can embody the rules of the relationship among the subcomponents. This relationship might represent an algorithm or solution to a problem, or it might support state changes not present in any of the individual parts. Algorithm parameters and/or hooks to state changes can be easily exposed through new properties and events. Finally, SuperComponents can be thought of as mini-apps. They are components themselves, and as such, lend themselves to a well-defined segregation from the rest of the project they are contained in. In team development environments, this means that developers most familiar with the problem and solution (whatever they be) can design the SuperComponents so that less-experienced developers can piece together the application with these building blocks.
  • 2. Disadvantages There are two disadvantages to making SuperComponents. First, visual SuperComponents require an additional Windows handle. Second, there is a small amount of overhead in the container parent component that holds all the sub-components. Before We Start It is useful to distinguish among the different roles developers and users take when dealing with components. There are three that we are concerned with: •Application Users (a.k.a. "users") will use applications built with the components we make. •Application Developers (a.k.a. "developers") will build applications using our components. •Component Writers (that's us!) will create components that will make is easier for developers to build applications and easier for users to use. It's important to note that as a component writer, you're designing for two customers. Visual Containment The steps to building a SuperComponent are roughly as follows: 1. 2. 3. 4. 5. 6. Design the layout of your components inside a form in Delphi, placing all the components inside a TPanel (or a descendant thereof). Select and copy the panel and paste it into a text file. Replace all instances of " = " with " := ", and add a semi-colon to the end of each line. Convert all DFM "object" declaration lines to appropriate object constructor code, setting the parent of all visual controls to the container panel. Clean up any remaining code. Bitmaps will need to be placed in resource files. Place this new pascal code inside a create constructor for your component. Within the constructor , group object sections under the appropriate sub-component creator. Let's use an example to illustrate these steps. We'll make an OK/Cancel/Help button combination. Inside Delphi, the layout looks like this (Note: the TPanel's border is set to none): Selecting, copying and pasting the above collection into a text file yields the following: object Panel1: TPanel Left = 114 Top = 10
  • 3. Width = 75 Height = 95 BevelOuter = bvNone TabOrder = 0 object OKButton: TButton Left = 0 Top = 0 Width = 75 Height = 25 Caption = 'OK' Default = True ModalResult = 1 TabOrder = 0 end object CancelButton: TButton Left = 0 Top = 35 Width = 75 Height = 25 Cancel = True Caption = 'Cancel' ModalResult = 2 TabOrder = 1 end object HelpButton: TButton Left = 0 Top = 70 Width = 75 Height = 25 Caption = 'Help' TabOrder = 2 end end This is the text representation of our SuperComponent group. Next, we need to convert this text to something that looks a little more like Object Pascal: object Panel1: TPanel Left := 114; Top := 10; Width := 75; Height := 95; BevelOuter := bvNone; TabOrder := 0; object OKButton: TButton Left := 0; Top := 0; Width := 75; Height := 25; Caption := 'OK'; Default := True; ModalResult := 1; TabOrder := 0; end object CancelButton: TButton
  • 4. Left := 0; Top := 35; Width := 75; Height := 25; Cancel := True; Caption := 'Cancel'; ModalResult := 2; TabOrder := 1; end object HelpButton: TButton Left := 0; Top := 70; Width := 75; Height := 25; Caption := 'Help'; TabOrder := 2; end end Now we're getting closer to what we want. The next step is to transfer the panel initialization to the component's constructor. We'll create the embedded controls here, too: constructor TOkCancelHelp.Create(AOwner: TComponent); { Creates an object of type TOkCancelHelp, and initializes properties. } begin inherited Create(AOwner); Width := 75; Height := 95; BevelOuter := bvNone; TabOrder := 0; OKButton := TButton.Create(Self); OKButton.Parent := Self; CancelButton := TButton.Create(Self); CancelButton.Parent := Self; HelpButton := TButton.Create(Self); HelpButton.Parent := Self; end; { Create } The three buttons, OKButton, CancelButton, and HelpButton need to be declared as fields of our new component. Our component's declaration looks like this: type TOkCancelHelp = class(TPanel) OKButton: TButton; CancelButton: TButton; HelpButton: TButton; private { Private declarations } protected { Protected declarations } public
  • 5. { Public declarations } constructor Create(AOwner: TComponent); override; published { Published properties and events } end; { TOkCancelHelp } Now let's take that converted DFM text and initialize the three buttons. Although you can do this inside our component's constructor, some VCL sub-component initialization code depends on a windows handle existing in its parent. At the time when our new SuperComponent is created (inside the Create constructor), this handle does not yet exist. So we need to find a method we can override in the TPanel that is called before the component is displayed and before its loaded method is called, but after a windows handle is assigned to the TPanel. The CreateWindowHandle method is the best place to do this. An override of this method, with the DFM initialization code inserted, looks like this: procedure TOkCancelHelp.CreateWindowHandle(const Params: TCreateParams); { Calls inherited CreateWindowHandle and initializes subcomponents. } begin inherited CreateWindowHandle(Params); with OKButton do begin Left := 0; Top := 0; Width := 75; Height := 25; Caption := 'OK'; Default := True; ModalResult := 1; TabOrder := 0; end; { OKButton } with CancelButton do begin Left := 0; Top := 35; Width := 75; Height := 25; Cancel := True; Caption := 'Cancel'; ModalResult := 2; TabOrder := 1; end; { CancelButton } with HelpButton do begin Left := 0; Top := 70; Width := 75; Height := 25; Caption := 'Help'; TabOrder := 2; end; { HelpButton } end; { CreateWindowHandle } And the component declaration now looks like this:
  • 6. type TOkCancelHelp = class(TPanel) OKButton: TButton; CancelButton: TButton; HelpButton: TButton; private { Private declarations } protected { Protected declarations } procedure CreateWindowHandle(const Params: TCreateParams); override; public { Public declarations } constructor Create(AOwner: TComponent); override; published { Published properties and events } end; { TOkCancelHelp } Finally, we need to add a register method so we can place our new component onto Delphi's component palette: procedure Register; begin RegisterComponents('CDK', [TOkCancelHelp]); end; { Register } Exposing Sub-Component Properties Grouping components together to create new SuperComponents is a pretty neat trick. One advantage is that it allows you to isolate many of the grouped components' properties from application developers. In fact unless you explicitly state otherwise, all of the grouped components properties will be hidden from developers! So how do you expose a sub-component property? You need to create two transfer methods that transfer the sub-component's properties to the outside world. For example, in our TOkCancelHelp component, it might be useful to expose the caption property so application writers can change it (e.g., for application development in a language other than English). Our transfer methods look a lot like the standard property Get and Set methods we're already familiar with. Here's the declaration for the OK button's caption property: type TOkCancelHelp = class(TPanel) . . . private { Private declarations } procedure SetCaption_OKButton(newValue: TCaption); function GetCaption_OKButton: TCaption; . .
  • 7. . published { Published properties and events } property Caption_OKButton: TCaption read GetCaption_OKButton write SetCaption_OKButton; end; These transfer methods pass the property values to and from the subcomponents. Their implementation looks like this: function TOkCancelHelp.GetCaption_OKButton: TCaption; { Returns the Caption property from the OKButton subcomponent. } begin result := OKButton.Caption; end; { GetCaption_OKButton } procedure TOkCancelHelp.SetCaption_OKButton(newValue: boolean); { Sets the OKButton subcomponent's Caption property to newValue. } begin OKButton.Caption := newValue; end; { SetCaption_OKButton } You may notice that there is no field variable for this property. All sub-component properties rely on the sub-components themselves for storage. Also notice that unlike most Set methods, this one doesn't check to see if the internal value is different from the passed-in newValue. We let the sub-component handle this check if necessary. Exposing Sub-Component Events Just as you would need to expose a sub-component's properties, you might also need to expose its events. The theory behind exposing sub-component events is similar to that used to expose properties. The difference is that with events, we need to store the event handler in a field variable (just like we would for a normal event). Additionally we have to hook in to any sub-componenent event that we want to make available to our component users, which means creating our own event handler for it. Event handlers must be assigned dynamically when the component is first created. The declaration for an exposed event and the event handler that surfaces it looks like this: type TOkCancelHelp = class(TPanel) . . . private { Private declarations } FOnClick_OKButton: TNotifyEvent; . . . procedure Click_OKButtonTransfer(Sender: TObject); published { Published properties and events } . { TNotifyEvent }
  • 8. . . property OnClick_OKButton: TNotifyEvent read FOnClick_OKButton write FOnClick_OKButton; end; Here, Click_OKButtonTransfer acts as the event handler. Notice that its type, TNotifyEvent, matches the expected type for the OnClick event (TNotifyEvent). The implementation for the transfer method looks like this: procedure TOkCancelHelp.Click_OKButtonTransfer(Sender: TObject); { Transfers the OKButton OnClick event to the outside world. } begin if assigned(FOnClick_OKButton) then FOnClick_OKButton(Self); { Substitute Self for subcomponent's Sender. } end; { Click_OKButtonTransfer } If you've triggered events before, you probably recognize this code. The if-clause checks to see if the event is assigned (typically performed via the Object Inspector at design-time), and if so calls it, passing a reference to itself (the SuperComponent) to the component user's event handler. So, the sub-component's event is handled by our transfer method, which in turn passes the event to a component user's event handler (that's right -- two event handlers for each event!). To hook up this chain of events, all we do is dynamically assign the event transfer method to the sub-component's event. We do this in the overridden CreateWindowHandle method: procedure TOkCancelHelp.CreateWindowHandle(const Params: TCreateParams); { Calls inherited CreateWindowHandle and initializes subcomponents. } begin inherited CreateWindowHandle(Params); with OKButton do begin . . . OnClick := Click_OKButtonTransfer; end; { OKButton } . . . end; { CreateWindowHandle } Hooking in to Sub-Component Events Sometimes you want to respond to a sub-component event without exposing it. The steps involved here are similar to those you'd follow to expose a sub-component event, except you don't declare the event (and you don't need the corresponding event field variable).
  • 9. type TOkCancelHelp = class(TPanel) . . . private { Private declarations } . . . procedure Click_CancelButtonHandler(Sender: TObject); { TNotifyEvent } published . . . end; The handler looks like this: procedure TOkCancelHelp.Click_CancelButtonHandler(Sender: TObject); { Handles the CancelButton OnClick event. } begin { Place your event-handling code here. } end; { Click_CancelButtonHandler } We glue it all together by dynamically assigning our handler to the sub-component event, just as we do when we want to expose a sub-component event: procedure TOkCancelHelp.CreateWindowHandle(const Params: TCreateParams); { Calls inherited CreateWindowHandle and initializes subcomponents. } begin inherited CreateWindowHandle(Params); . . . with CancelButton do begin . . . OnClick := Click_CancelButtonHandler; end; { CancelButton } . . . end; { CreateWindowHandle } Summary
  • 10. SuperComponents promote consistency and reuse. They can embody commonly-used configurations of controls, dramatically cutting development time and slashing code size. And the techniques involved here are not difficult to master.
  • 11. Recommended Reading The following books were current at the time of this writing. Make sure you check for the most recent edition. Developing Custom Delphi Components by Ray Konopka; edited by Jeff Duntemann Coriolis Group Books (800) 410-0192 or (602) 483-0192 http://www.coriolis.com 585 pages ISBN 1-883577-47-0 This book is highly recommended if you need additional information on component building or building business components. It is filled with useful information and excellent examples. The explanations are clear and easy to understand. In addition, Ray Konopka’s TRzBusinessComponent, included with the CDK, is presented and detailed in his book. Secrets of Delphi 2 -- Exposing Undocumented Features of Delphi by Ray Lischner Waite Group Press 831 pages ISBN 1-57169-026-3 This is an amazing book, packed with valuable information you can’t get anywhere else. Also contains excellent coverage of property editors, component editors, and other advanced component-building topics. The Delphi Magazine Edited by Chris J G Frizelle iTec Publishing To subscribe in the UK: Tel/Fax: +44 (0) 181 460 0650 Email: 70630.717@compuserve.com To subscribe in the US: Phone: (802) 244-7820 Email: 70602.1215@compuserve.com This magazine consistently contains excellent technical articles on Delphi-related subjects. Also contains a monthly column by Bob Swart (a.k.a. Dr. Bob) on component building in Delphi.
  • 12. Design Patterns--Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Foreword by Grady Booch Addison-Wesley Publishing Company 395 pages ISBN 0-201-63361-2 This book organizes and presents a catalog of proven object-oriented solutions for architecting complex systems that you can apply to your own specific applications. These design constructs are labeled, allowing your development team to share a common vocabulary. The CDK help file references two of the design patterns in this book: the Proxy pattern and the Template Method pattern. The examples are in C++, but the patterns apply to all programming languages. Component Writer’s Guide by Borland International, Inc. (408) 431-1000 156 pages The Component Writers Guide is a lean but important resource for learning about how to create working components and to ensure that components you write are well-behaved parts of the Delphi environment. The book guides you to writing components that fit in well with any Delphi application. About the Author Mark Miller is the lead software engineer at Eagle Software. Mark holds the primary vision for the Component Developer Kit for Delphi (the CDK) reAct, a component testing tool for Delphi, as well as several other Delphi add-ons currently in development. He has been programming in Pascal, Object Pascal, and Delphi for nearly 16 years. He can be reached at markm@eagle-software.com, or via CompuServe at 76043,2422.