Declaring the Property

From RAD Studio
Jump to: navigation, search

Go Up to Determining What to Draw

When you declare a property, you usually need to declare a private field to store the data for the property, then specify methods for reading and writing the property value. Often, you don't need to use a method to read the value, but can just point to the stored data instead.

For the shape control, you will declare a field that holds the current shape, then declare a property that reads that field and writes to it through a method call.

Add the following declarations to TSampleShape:

   TSampleShape = class(TGraphicControl)
     FShape: TSampleShapeType;  { field to hold property value }
     procedure SetShape(Value: TSampleShapeType);
     property Shape: TSampleShapeType read FShape write SetShape;
 class PACKAGE TSampleShape : public TGraphicControl
     TSampleShapeType FShape;
     void __fastcall SetShape(TSampleShapeType Value);
     __property TSampleShapeType Shape = {read=FShape, write=SetShape, nodefault};

Now all that remains is to add the implementation of SetShape.