Declaring A New Constructor (C++)

From RAD Studio
Jump to: navigation, search

Go Up to Introduction to component creation Index

Each new component must have a constructor that overrides the constructor of the class from which it was derived. When you write the constructor for your new component, it must always call the inherited constructor.

Within the class declaration, declare a virtual constructor in the public section of the class.

For example,

class PACKAGE TNewComponent : public TComponent
{
public:
  virtual __fastcall TNewComponent(TComponent* AOwner);
};

In the .CPP file, implement the constructor:

__fastcall TNewComponent::TNewComponent(TComponent* AOwner): TComponent(AOwner)
{
}

Within the constructor, you add the code you want to execute when the component is created.