RAD Studio |  |

Declaring A New Constructor (C++)

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,

Copy Code

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

In the .CPP file, implement the constructor:

Copy Code

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

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

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!