C ++ Builder master advanced (3) Design DBTreeView Components with BCB (Summary)

zhaozj2021-02-16  26

Design DBTreeView component summary with BCB

Continued two last functions, do you feel very wondering: What is this function to do? Let me listen to me slowly: I use this function mainly to implement custom property editing. Careful readers must remember that there are three key data members in the control I designed: ParentID, PrimaryidField, DisplayField, what is the function of these three members? I believe I don't have to say more. In order to make them more user-friendly, I chose to display it in the way, and the specific content is coming from the fields in the data table, so naturally, I use TfieldNameProperty, through customization, I Realized the customization of the property editor.

TTYPEINFO * ANSISUSTRINGTYPEINFO (VOID)

{

// Define type information

TtypeInfo * TypeInfo = New TTYPEINFO;

TYPEINFO-> Name = "ANSISTRING";

TypeInfo-> Kind = tklstring;

Return TypeInfo;

}

Namespace DBTREEVIEW

{

// Register components

Void __fastcall package register ()

{

RegisterPropertyEditor (AnsistringTypeInfo (), __classid (tdbtreeview), "parentidfield", __classid (tfieldNameProperty); // Register Properties

RegisterPropertyEditor (AnsistringTypeInfo (), __classid (tdbtreeview), "primaryidfield", __classid (tfieldNameProperty); // Register Property

RegisterPropertyEditor (AnsistringTypeInfo (), __ClassId (TDBTreeView), "DisplayField", __ClassId (TfieldNameProperty); // Register Property

Tcomponentclass classes [1] = {__classid (tdbtreeView)};

Registercomponents ("Data Controls", Classes, 0); // Register Components

}

}

So far, I have given all the ideas and code of DBTreeView with BCB. I don't know how you feel? If you feel good, you will encourage it; if you feel bad, you can also speak (it seems to be a rivers and lakes selling arts), I hope everyone will make progress!

Through the preparation of this component, should you use BCB to develop some components? Here I will summarize the key points in this component design and provide a suggestion for you later:

1. Write a new component first, first consider which birth. You need to be familiar with the inheritance relationship of VCL structures, approximately a variety of visual components, unconventional components, window components, and the like. It is recommended that you look at "C Builder 5 Developer Guide" and "C Builder Depth Adventures".

2. Event definition. The event is actually the process you want to do when something is happening. Take the method of custom belt parameters in DBTREEVIEW.

typedef void __fastcall (__closure * TDBTVSetImageIndexEvent) (System :: TObject * Sender, int ID, int ParentID, int Level, int & ImageIndex, int & SelectedIndex); TDBTVSetImageIndexEvent custom event types, ID, ParentID other event required parameters . Then you can define this incident:

Private:

TDBTVSetImageIndexevent FonsetImageIndex;

__publish:

__property tdbtvsetimageIndexevent oversetimageindex = {read = FonsetImageIndex, Write = FonsetImageIndex};

3. Define the message. Although there is no message in my dbtreeview, the role of the message is not to be ignored. The way to define messages in BCB is as follows:

Private:

VOID __FASTCALL ONMYMESSAGE (TMESSAGE & MSG); / / Define Message Functions

Begin_MESSAGE_MAP

Message_Handle (Message, Message Type, Message Function)

END_MESSAGE_MAP (parent class)

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

New Post(0)