Creating and Registering the Modified Component
Go Up to Modifying an existing component Index
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:
- Call the component's unit Memos.
- Derive a new component type called TWrapMemo, descended from TMemo.
- Register TWrapMemo on the Samples page of the Tool palette.
- The resulting unit should look like this:
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);
}
}
#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.