Write VCL controls with C ++ Builder 6

zhaozj2021-02-16  52

Write VCL controls with C Builder 6

Warton 2002.12 Xi'an

If the programmer in the development tool using Borland today, many programmers began to turn from VC , BC and other tools to C Builder (hereinafter referred to as BCB, Borland C Builder) and Delphi. To use these two development tools, you will use the VCL (Visual Component Library Visual Control Library). About writing VCL's Delphi's books and materials are quite, but use C to write, the information is much less.

How to write VCL controls with a C language is a topic that many learning and use BCB. How to write? Below, I will write VCL's ideas and methods to make a brief introduction, and give a simple example so that the majority of C enthusiasts can be familiar with and use BCB to better write programs.

First, give a VCL inheritance relationship and structural diagram (TFORM as an example):

Tobject | TPERSIStent | TComponentt | TControl | TwinControl | TscrollingwinControl | TCUSTOMFORM | TFORM

As you can see from the above figure: TOBJECT is the parent class of all derived classes, and the tComponent is the parent class of all visual components, and TwinControl is the parent class of all window classes. Only components inherited from TwinControl have a Handle property. Since BCB and Delphi use the same class VCL, the programmer can refer to Delphi's book about component inheritance. However, writing VCLs with C is quite a large difference with the use of Pascal (using Object Pascal in Delphi).

After a probably understanding of the VCL, you still need to understand some things: Write the VCL class written with C or a C class, but it has some differences from the standard C class. The most important of these is that the VCL component does not have multiple inheritance. We can see this from the inheritance relationship diagram of TFORM.

Let's take an example, simply talk about the steps of using BCB to write VCL:

1. Create a component package: package. Select the New option in the File menu of C Builder, then in the new items window that pops up, click OK, as shown in Figure 1-2. Then save the package as MyComponent.bpk.

Figure 1-2 Create a new package

2. Create a new component. Click the Add button on the Package window, as shown in Figure 1-3.

Figure 1-3 Package Window

3. Select the New Component page in the pop-up Add-window, as shown in Figure 1-4.

Select Inherit in TPANEL, name the class name: UserControl, the Palette Page is changed to User, then determine.

Figure 1-4 Creating a new component

After the above steps, a simple package can already be installed on the control panel of the BCB. Now you just click the Compile button of the Package window, click the Install button to install this component to a palette of the label as My.

Open your MY tab on the BCB control panel, you will be able to see an icon and panel, which is the performance form after the TMYComponent class is installed. So far, a simple control is already available. But it doesn't have a special feature, it just simply inherits the TPANEL control, and all attributes and events of TMYComponent are TPANEL, I don't define new properties, methods, and events. That is, TMYCOMMPONENT and TPANEL are now basically exactly the same (from functional). The control is written, do you think it is very simple to write to the BCB write control? Yes, you can write a control for a few mice, it is really too simple. But this is just the beginning, and it is still behind.

Below, the method of writing a complete VCL control is prepared from writing methods, attributes, and events, respectively.

(Endlessly)

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

New Post(0)