RAD Studio |  |

Declaring the Property

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:

Copy Code

    type
      TSampleShape = class(TGraphicControl)
      private
        FShape: TSampleShapeType;  { field to hold property value }
        procedure SetShape(Value: TSampleShapeType);
      published
        property Shape: TSampleShapeType read FShape write SetShape;
      end;

Copy Code

    class PACKAGE TSampleShape : public TGraphicControl
    {
    private:
        TSampleShapeType FShape;
        void __fastcall SetShape(TSampleShapeType Value);
    __published:
        __property TSampleShapeType Shape = {read=FShape, write=SetShape, nodefault};
    };

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

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