RAD Studio
ContentsIndex
PreviousUpNext
Declaring the Class Fields

Each class a component owns must have a class field declared for it in the component. The class field ensures that the component always has a pointer to the owned object so that it can destroy the class before destroying itself. In general, a component initializes owned objects in its constructor and destroys them in its destructor. 

Fields for owned objects are nearly always declared as private. If applications (or other components) need access to the owned objects, you can declare published or public properties for this purpose. 

Add fields for a pen and brush to the shape control:

type
  TSampleShape = class(TGraphicControl)
  private            { fields are nearly always private }
    FPen: TPen;      { a field for the pen object }
    FBrush: TBrush;  { a field for the brush object }
    .
    .
    .
  end;

 

class PACKAGE TSampleShape : public TGraphicControl
{
private:               // data members are always private
    TPen *FPen;        // a data member for the pen object
    TBrush *FBrush;    // a data member for the brush object
    .
    .
    .
};
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!