From 8a817c6d142027e2923ffe8af42ab99ea88bbd8d Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 7 Feb 2006 04:44:03 +0000 Subject: Completed the tutorial about creating new controls. --- .../protected/pages/Controls/NewControl.page | 46 +++++++++++++++------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'demos') diff --git a/demos/quickstart/protected/pages/Controls/NewControl.page b/demos/quickstart/protected/pages/Controls/NewControl.page index 76999e79..15b42d13 100644 --- a/demos/quickstart/protected/pages/Controls/NewControl.page +++ b/demos/quickstart/protected/pages/Controls/NewControl.page @@ -92,7 +92,10 @@ In the above, Label.Text is a subproperty of LabeledTextBox, w

Extending Existing Controls

-Extending existing controls is the same as conventional class inheritance. It allows developers to customize existing control classes by overriding their methods or providing new functionalities. The difficulty of the task depends on how much an existing class needs to be customized. +Extending existing controls is the same as conventional class inheritance. It allows developers to customize existing control classes by overriding their properties, methods, events, or creating new ones. +

+

+The difficulty of the task depends on how much an existing class needs to be customized. For example, a simple task could be to customize TLabel control, so that it displays a red label by default. This would merely involves setting the ForeColor property to "red" in the constructor. A difficult task would be to create controls that provide completely innovative functionalities. Usually, this requires the new controls extend from "low level" control classes, such as TControl or TWebControl.

In this section, we mainly introduce the base control classes TControl and TWebControl, showing how they can be customized. We also introduce how to write controls with specific functionalities, such as loading post data, raising post data and databinding with data source. @@ -100,8 +103,13 @@ In this section, we mainly introduce the base control classes TControl

Extending TControl

-TControl is the base class of all control classes. It implements the following properties and methods that are commonly used in derived control classes, +TControl is the base class of all control classes. Two methods are of the most importance for derived control classes:

+ +Other important properties and methods include:

Extending TWebControl

-getTagName() -addAttributesToRender -renderBeginTag -renderContents -renderEndTag +TWebControl is mainly used as a base class for controls representing HTML elements. It provides a set of properties that are common among HTML elements. It breaks the TControl::render() into the following methods that are more suitable for rendering an HTML element: +

+ +

+When rendering the openning HTML tag, TWebControl calls getTagName() to obtain the tag name. Derived classes may override this method to render different tag names.

-

+

Creating Controls with Special Functionalities

+

+If a control wants to respond to client-side events and translate them into server side events (called postback events), such as TButton, it has to implement the IPostBackEventHandler interface. +

+

+If a control wants to be able to load post data, such as TTextBox, it has to implement the IPostBackDataHandler interface. +

+

+If a control wants to get data from some external data source, it can extend TDataBoundControl. TDataBoundControl implements the basic properties and methods that are needed for populating data via databinding. In fact, controls like TListControl, TRepeater are TDataGrid are all derived from it. +

PostBackHandler PostBackEvnetHandler DataBoundControl -- cgit v1.2.3