Step 6 - Add Properties to Change the Look and Feel

From Appmethod Topics
Jump to: navigation, search

Go Up to Creating a FireMonkey Primitive Control

You can enhance the TRegularPolygon component and enable changes to its look and feel. For example, you can change the background color.

Other FireMonkey primitive components typically have the following look and feel properties:

  • Fill property
  • Stroke property
  • StrokeCap property
  • StrokeDash property
  • StrokeJoin property
  • StrokeThickness property

To be able to use these properties, reintroduce them as published properties.

The interface section of the TRegularPolygon component should look like this:

  TRegularPolygon = class(TShape)
    { Private declarations }
    FNumberOfSides: Integer;
    FPath: TPathData;
    procedure SetNumberOfSides(const Value: Integer);
    { Protected declarations }
    procedure CreatePath;
    procedure Paint; override;
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function PointInObject(X, Y: Single): Boolean; override;
    { Published declarations }
    property NumberOfSides: Integer read FNumberOfSides write SetNumberOfSides;
    property Fill;
    property Stroke;
    property StrokeCap;
    property StrokeDash;
    property StrokeJoin;
    property StrokeThickness;

In the Project Manager, build and install the package. Go back to the TestRegularPolygonUnit. Now you have the options to change the look and feel of your new component.