The Component wizard simplifies the initial stages of creating a component. When you use the Component wizard, you need to specify:
The unit looks like this:
unit MyControl; interface uses Windows, Messages, SysUtils, Types, Classes, Controls; type TMyControl = class(TCustomControl) private { Private declarations } protected { Protected declarations } public { Public declarations } published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyControl]); //In CLX, use a different page than 'Samples' end; end.
//header file #ifndef NewComponentH #define NewComponentH //--------------------------------------------------------------------------- #include <SysUtils.hpp> #include <Controls.hpp> #include <Classes.hpp> #include <Forms.hpp> //--------------------------------------------------------------------------- class PACKAGE TNewComponent : public TComponent { private: protected: public: __fastcall TNewComponent(TComponent* Owner); __published: }; //--------------------------------------------------------------------------- #endif
//implementation file #include <vcl.h> #pragma hdrstop #include "NewComponent.h" #pragma package(smart_init); //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // static inline void ValidCtrCheck(TNewComponent *) { new TNewComponent(NULL); } //--------------------------------------------------------------------------- __fastcall TNewComponent::TNewComponent(TComponent* Owner) : TComponent(Owner) { } //--------------------------------------------------------------------------- namespace Newcomponent { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TNewComponent)}; RegisterComponents("Samples", classes, 0); //In CLX use a different page than Samples } }
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|