You create every component the same way: you create a unit, derive a component class, register it, and install it on the Tool palette. This process is outlined in Creating a new component.
For this example, follow the general procedure for creating a component, with these specifics:
unit Memos; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, StdCtrls; type TWrapMemo = class(TMemo) end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TWrapMemo]); end; end.
#include <vcl.h> #pragma hdrstop #include "Yelmemo.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(TYellowMemo *) { new TYellowMemo(NULL); } //--------------------------------------------------------------------------- __fastcall TYellowMemo::TYellowMemo(TComponent* Owner) : TMemo(Owner) { } //--------------------------------------------------------------------------- namespace Yelmemo { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TYellowMemo)}; RegisterComponents("Samples", classes, 0); //"Common Controls" in CLX applications } }
#ifndef YelMemoH #define YelmemoH //--------------------------------------------------------------------------- #include <sysutils.hpp> #include <controls.hpp> #include <classes.hpp> #include <forms.hpp> #include <StdCtrls.hpp> //--------------------------------------------------------------------------- class PACKAGE TYellowMemo : public TMemo { private: protected: public: __published: }; //--------------------------------------------------------------------------- #endif
If you compile and install the new component now, it behaves exactly like its ancestor, TMemo. In the next section, you will make a simple change to your component.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|