Saturday, October 23, 2010

Secret to create components


1. To create component class declaration
class PACKAGE new class name: public ancestor class name
(
private:
Private data: (1) internal private use (2) release the real data retention properties (3) release event data retention
(1,2,3) private data generally in the constructor initialization, (3) the general initialization of the event associated with the ancestors.
Usually call the ancestor method to facilitate the direct ancestor of the type often with variable preservation: typedef ancestor class name Inherit;
Private methods: internal use only in the class definition, do not want to be successor to use, does not want the public to use. (Try to write generic functions)
protected:
Protection of data: it seldom used.
Protection method: virtual function normally. Internal use in the class definition, the object can not be directly invoked, and whether or not control of the public to its derived class
The derived class can redefine the method, and may be open.
public:
Public data: general properties, but not released (ie the design phase can not operate) property is not real data
Private data needed to save the property, operating property through the method. Commonly defined as:
Mode 1: __property AnsiString ItemData = (read = FItemData, write = FItemData, default = "A");
Mode 2: __property AnsiString ItemData = (read = GetItemData, write = SetItemData, default = "A");
FItemData save their data private office, GetItemData (), SetItemData () is the realization of read-write
Function, in addition to its internal data, can also be added to set the appropriate handling code, this part of the deal is an
Of greatest strength. That is achieved by directly modifying properties of both reading and writing of data can achieve the code office
Management, but users are only made sense if the data changes, it is this "side effect" brought about.
Also, if the changes to the property does not need to respond to treatment only with the definition of mode 1 on the line.
Public methods: implementation class package, change the data members of the public functions through. (Method)
Re-defined functions are usually the first call the ancestor class of the method Inherit:: XXX (); (Inherit have stated, XXX table function name),
And then write their own code to make the deal.

__published:
Post properties: with the public part of the property, except that the release properties in the design phase can be observed directly through the object to modify.
Published property ancestor class, it is best to confirm this. In passing that the method statement should not be written in the Office
Properties can also be written in public or private, but they are not in the design of access, private property only in
Internal use are not available to users. Writing component should be as much as possible with property, rather than utilizing method. Not only property
Only the work done by the method to complete.

Post event:
1. Ordinary event: the only parameter only TObject * Sender, general use TNotifyEvent (pointer type)
Such as: __property TNotifyEvent nExit = (read = FnExit, write = FnExit);
As with the attributes necessary to save the event private data pointer. TNotifyEvent FnExit;
Another is the event handling code. void __fastcall MynExit (System:: TObject * Sender)
Its implementation in the code from the FnExit (Sender) statement trigger event; (Note that the event handler return value void)
2. Special events:
First: the definition of event types require pointers (similar to the definition of function pointers)
typedef void __fastcall (__closure * TKeyDownEvent) (System:: TObject * Sender,
WORD & Key, TShiftState Shift);
Second: to have the data depository. Private office in a statement: If TKeyDownEvent FnKeyDown;
Re: have the corresponding event handler is generally protected Department statement. As
protected:
virtual void __fastcall MynKeyDown (System:: TObject * Sender, WORD & Key,
TShiftState Shift); code often FnKeyDown (Sender, Key, Shift)
Finally: Set connection (need to provide the first three: Event pointer type, data repository variable, the event handler).
__property TKeyDownEvent nKeyDown = (read = FnKeyDown, write = FnKeyDown);

);

2. Component Inspection and Registration
static inline void ValidCtrCheck (new class name *)
(
new new class name (NULL);
)
Ensure that the control statement, there is no pure virtual functions, virtual base class for instance can not be generated.

namespace namespace
(
void __fastcall PACKAGE Register ()
(
TComponentClass classes [1] = (__classid (the new class name));
RegisterComponents ("their package name", classes, 0);
/ / Add property editors also note RegisterPropertyEditor (...)
)
)
Name space is a C + + features, use this Register () function can distinguish the other controls. This name must conform to specifications,
With the control file name where relevant. If TMyButton in mybutton.cpp in this namespace are Mybutton. With
New Component dialog box to generate new components, without considering the issue.






Recommended links:



DivX To IPod



Copper plate etching to create text in Photoshop



Create a simple Window



CLEAR links in the production of hidden "oil tiger"



Five operators commitment to cancel the contract monthly fee Controversy pending Overlord



DivX to Zune



Dreamweaver MX 2004 from scratch (7)



wlanapi dll MISSING error beware amp repair



Easy to use Telnet Servers



New System Utilities



SARFT issued the first batch of 3G Licenses audio-visual



3GP to MPEG



Liang Dong, vice president of Baidu's RESIGNATION



CorelDRAW based cartoon series (1)



Easy-speed Run 47 Hours To Restore The Secret



No comments:

Post a Comment