Through examples to see the entire process of VCL components (1)

zhaozj2021-02-16  42

Through examples, VCL Components Development Process

This article is an learning summary for me to learn before, and a review of my learning process. This article uses a simple example to display all aspects of VCL component development, this article is for beginners who are about to learn components. If you are familiar with the development or think of this content is too basic, then this article is useless. Read this article, suppose you are familiar with Delphi's normal programming and VCL structure level, and some important keywords: Published, Property, etc. (Note: This article is built in Delphi5.0 and above)

In this article we will establish a sum of time-related components, this component has the following basic functions by setting its different states: 1. Display the current time of the system (including setting alarm). 2, running a table. 3, countdown. This is a simple example, but we will use as much as possible in this example to use a variety of features in component development, you can read the features selected by this article in this article:

· Components and component packages

· Component's attribute category

· Component's property editor

· Component editor

I. Components and component packages, and some file types you should know:

The relationship between components and component packages is like the relationship between Unit and Engineering files in ordinary engineering. Usually, the components you have installed are released in the form of a component package, and there are many components in a component package, in component development, The component package is the project of the project. To start developing our components (we call him TCLOCK) and include it in our own component package (ClockPackage), we choose Fileànewàother in the new window in the pop-up page Select Package New A component package, get a component package window, view the original file (.dpk) of this component package, get the following code:

Package clockpackage;

{$ R * .res}

{$ Align 8}

{$ Assertions on}

.......

.......

{$ Description 'ot clock pack'}

{$ IMPLICIILD OFF}

Requires

RTL;

End.

This file is actually an engineering file in component development. The Requires keyword indicates a list of component packages required for component packages. With the components (similar to unit files) to the component package, you will also see the Contains keyword, indication The components contained in the component package, you can add new components and delete existing components through the Add and Remove in the component package window. In addition, a large number of compiler switches contained in this code can be set in Options on the component package form. Here, you need to add three important properties (all in Options): Designtime Only, Runtime Only, Designtime and Runtime (these 3 words Means if there is a friend who knows the English foundation), for most Component package We can choose the last one, but some component packets are designed as only runtime (so that you can use this component to develop, you can't run separately, the component pack cannot be installed), some component packs are Designed to be designed (this will have a more detailed description thereafter).

Understand the components and component packages, we do some of the files you have not seen in the development of component development: DPK files are original code for components; BPL files, components compile results, without publishing DPK In the case, you can install the components to delphi (ProjectàOptionsàPackagesàAdd); PAS is here the original code of the component in the component package; the DCU is compiled by PAS, when you select the component to incorporate the component package (Contains keyword) You can choose to release the original code or not post (DCU file); DCP If you use the component as a runtime component, the connector will use the file. Second, began to develop components:

After understanding the above knowledge, we can start developing components! Click Add in the Component Form, select the Newcomponent page, select which class is to inherit from the first combo box (usually new components are developed by inheriting existing components), due to this component The main role is to display the text information of time, running, countdown, so we choose to inherit from TCUSTOMLABEL (because we don't need TLabel's full function, we chose TCUSTOMLABEL that can hide the TLabel property and have selected to publish its properties. class). Next, take a name Tclock for our new component, then specify which page we want to install the component to which page, here we type a clockandtime page, which will appear in the registercomponents (later, select) After saving the path (preferably put it and the component DPK package in the same directory). This is the file that has already been built under the Contains in the component package form, double-click it to start writing code.

In the code, we need to pay attention to a new process in the interface section: Procedure Register; (Note: Delphi specifies that the REGSTER R must be capitalized, this is a reserved word), this process is necessary for each component, it is completed Registration of components, including components itself, and registration such as multiple component features such as attribute editing):

PROCEDURE register;

Begin

Registercomponents ('ClockandTime', [TCLOCK]);

// This process registered component itself, noticed the clockandtime page that the previous definition is?

// Here there will be some new processes, including the attribute category of registration components, and so on.

In the next article we will give all the original code of this component. (Endlessly)

转载请注明原文地址:https://www.9cbs.com/read-27355.html

New Post(0)