// ******************************************************** *********** //
// ****************** Create component probe ******************* //
// ****************** 2000.08.15 leemingsong ************* //
// ******************************************************** *********** //
1. Creating a class declaration of components
Class Package New Category: Public Ancestral Class Name
{
Private:
Private data: (1) Internal private (2) Real Data Save (3) Publishing Event Data Save
(1, 2, 3) Private data initialization typically in the constructor, the initialization of (3) is generally connected to the ancestor.
It is usually convenient to directly call ancestors, often saving the ancestral type variable: TypeDef ancestors class inherit;
Private way: Only use within the class definition, do not want to be inherited, do not want to use it. (Try to write universal functions)
protected:
Protect data: Generally, it is very small.
Protection method: Generally a virtual function. Internal use during class definition, the object cannot be called directly, and the disclosure is controlled to the assignment
Its derived class can define this method and can be disclosed.
PUBLIC:
Public data: General attribute, but not published (ie design period cannot be operated) attribute is not true data
You need private data to save properties, and the operation properties are passed by way. Commonly defined as:
Method 1: __ proteTy Ansistring ItemData = {read = fitemdata, Write = fitemdata, default = "a"};
Method 2: __ proteTy Ansistring ItemData = {read = GetItemData, Write = setItemData, default = "a"};
Fitemdata is its data private storage, GetItemData (), setitemdata () is a read and write
Function, in addition to setting the data outside the data, this processing is
The biggest advantage of sex. That is, the code to achieve both the data read and write and the code can be achieved by direct modification.
If the user's feelings seem to have made only data, it is this "side effect".
In addition, if you modify the attribute, you don't need to be processed, just use only the definition method 1.
Public method: Implement the package package, change the data member through the public function. (Method)
Refine the function of the function of the function in first, the method of the ancestry, inherit :: xxx (); (Inherit has explained, xxx table functions),
Then write the processing code you want to do.
__publish:
Publish attributes: The attribute of the same public part is that the publishing attribute can be modified directly through the object observation directly in the design period.
The ancestor class has been published, it is best to confirm this. By the way, it should not be written in the release statement.
Attributes can also be written into public or private, but they cannot be accessed during design, and private properties are only
Internal use is not available to users. Write components should use properties as much as possible, and less use. Only attributes cannot be
The completed work is completed by the method.
Publishing events:
1. Ordinary event: The only Tobject * Sender with parameters, generally use TNOTIFYEVENT (pointer type)
Such as: __ protety tnotifyevent oneXIT = {read = FONEXIT, WRITE = FONEXIT};
A private data is required as the attribute to save the event pointer. TNOTIFYEVENT FONEXIT; additional event processing code. Void __fastcall myonexit (System :: TOBJECT * SENDER)
In fact, the current code is triggered by a FONEXIT statement statement; (note the event handler Return VOID)
2. Special events:
First: You need to define event type pointers (similar to the definition of function pointers)
Typedef void __fastcall (__closure * tkeydownevent) (System :: Tobject * Sender,
Word & Key, TshiftState Shift;
Second: There must be a data saving. Declaring at the Private: such as TKEYDOWNEVENT FONKEYDOWN;
Again: There is a corresponding event handler to declare at the Protected. Such as
protected:
Virtual void __fastcall myonkeydown (System :: TOBJECT * Sender, Word & Key,
TshiftState Shift; FonkeyDown (Sender, Key, Shift) is often available in the code.
Finally: Set the connection (the top three: event pointer type, data storage variable, event handler).
__property tkeydownevent onkeydown = {read = fonkeydown, Write = fonkeydown};
}
2. Component inspection and registration
Static Inline Void Validctrcheck (new class *)
{
New New Category (NULL);
}
Make sure there is no pure virtual function in this control statement because the virtual base class cannot generate an instance.
Namespace namespace
{
Void __fastcall package register ()
{
TcomponentClass classes [1] = {__ClassID (new class)};
RegisterComponents ("Benname", Classes, 0);
// can also add attribute editor Description RegisterPropertyEditor (...)
}
}
The namespace is a C feature that can be distinguished from other controls. This name must meet the specifications.
Related to the file name of the control. If TMYBUTTON is in myButton.cpp, this namespace is MyButton.
The New Component dialog box generates a new component without considering this problem.
I am willing to have friends with the world, please tell me any idea, please tell me E-mail: leemingsong@163.net