TFMXObject - FireMonkey Guide

Back to FireMonkey Library

Unit: FMX.Types
Parent: TComponent

TFMXObject is the root of all FireMonkey objects and components. It’s chief function is the maintenance of a list of child TFMXObjects (the Children property) plus a few useful utility methods and properties.

Child and Parent Management


When you create a descendant of TFMXObject you will probably want it to be a child of another TFMXObject descendant. You can do this by either setting the Parent property or calling AddObject on the parent (both methods are equivalent).

procedure TForm1.FormCreate(SenderTObject);
:= TButton.Create(Self);
Button.Parent := Panel1;
//or Panel1.AddObject(Button);

In this case the form is the owner of Button and the button will be destroyed when the form is destroyed but Panel1 is the parent. If the child is a control then it’s position and sizing will be relative to parent and certain events, such as keyboard and mouse handling, will trickle either down from the parent or up to the parent.

In the example above both Panel1 and Button have the same owner (Form1) but it’s perfectly possible for an object to either have either no owner or a different owner to it’s parent.

For example it’s possible to create a component on one form (say Form1) and set it’s parent to be a component on a different form (Form2). In this case Form1 will be the owner but the control (and any children) will appear as a child of the control on Form2. We’ll explore this in more depth in Embedding Forms in Other Forms.

Note that the owner of a component is responsible for freeing it. If there is no owner (nil is passed to Create) you, as the developer, are responsible for the object’s lifecycle.

Child Management

Children are accessed through the Children and ChildrenCount properties.

procedure TForm1.Button1Click(SenderTObject);
for Item in Panel1.Children do
Item is TButton then
(Item).Text := TButton(Item).Text.ToUpper;

procedure TForm1.Button2Click(SenderTObject);
for := 0 to Panel1.ChildrenCount-do
Panel1.Children[I] is TButton then
(Panel1.Children[I]).Text := TButton(Panel1.Children[I]).Text.ToLower;

Child and Parent Management Members

//Returns the component we are a child of, which may not be the immediate parent
function GetParentComponentTComponentoverride;
procedure AddObject(const AObjectTFmxObject);
procedure InsertObject(IndexInteger; const AObjectTFmxObject);
procedure RemoveObject(const AObjectTFmxObject); overload;
procedure RemoveObject(IndexInteger); overload;
ContainsObject(AObjectTFmxObject): Booleanvirtual;
procedure Exchange(const AObject1AObject2TFmxObject); virtual;
procedure DeleteChildren;
IsChild(AObjectTFmxObject): Booleanvirtual;
//Front and back (first and last) of Children list
procedure BringToFrontvirtual;
procedure SendToBackvirtual;
procedure AddObjectsToList(const AListTFmxObjectList);
procedure Sort(CompareTFmxObjectSortCompare); virtual;
property ChildrenCountInteger read GetChildrenCount;
property ChildrenTFmxChildrenList read FChildrenList;
property ParentTFmxObject read FParent write SetParent;
//a.k.a. Parent.Children.IndexOf(Self)
property IndexInteger read GetIndex write SetIndex

Animating Properties

TFMXObject includes a number of procedures for animating it’s properties. In other words they vary the value of a property over time.

procedure AnimateFloat(const APropertyNamestring; const NewValueSingleDurationSingle 0.2;
ATypeTAnimationType TAnimationType.atIn;
AInterpolationTInterpolationType TInterpolationType.itLinear);
procedure AnimateFloatDelay(const APropertyNamestring; const NewValueSingleDurationSingle 0.2;
DelaySingle 0.0ATypeTAnimationType TAnimationType.atIn;
AInterpolationTInterpolationType TInterpolationType.itLinear);
procedure AnimateFloatWait(const APropertyNamestring; const NewValueSingleDurationSingle 0.2;
ATypeTAnimationType TAnimationType.atIn;
AInterpolationTInterpolationType TInterpolationType.itLinear);
procedure AnimateInt(const APropertyNamestring; const NewValueIntegerDurationSingle 0.2;
ATypeTAnimationType TAnimationType.atIn;
AInterpolationTInterpolationType TInterpolationType.itLinear);
procedure AnimateIntWait(const APropertyNamestring; const NewValueIntegerDurationSingle 0.2;
ATypeTAnimationType TAnimationType.atIn;
AInterpolationTInterpolationType TInterpolationType.itLinear);
procedure AnimateColor(const APropertyNamestringNewValueTAlphaColorDurationSingle 0.2;
ATypeTAnimationType TAnimationType.atIn;
AInterpolationTInterpolationType TInterpolationType.itLinear);
procedure StopPropertyAnimation(const APropertyNamestring); 

Float routines animate a floating point value, such as the Singles commonly used as co-ordinates in FireMonkey. Int routines animate an integer property. The Color routine animates a TAlphaColor property.

Delay routines start the animation after an initial pause. Wait routines wait until the animation is complete before returning, and are useful for chaining animations. Other routines return immediately and can be used to animate a number of properties in parallel.

APropertyName is the name of a property as a string. This can be a qualified name such as ‘Position.X’ to access sub-properties. NewValue is the value the property will animate towards and finish on. Duration is the time in seconds which the animation will take. AType and AInterpolation determine the formula to use for the animation and are visualised in Interpolation and AnimationType Illustrated.

The following example moves a button to the top-left of it’s parent.

procedure TForm1.Button1Click(SenderTObject);

Meta Storage

The following are available for storing any data you wish and supplement the integer Tag property of TComponent. You should not, however, use them in a style since FireMonkey sometimes uses them for itself.

property TagObjectTObject read FTagObject write FTagObject;
property TagFloatSingle read FTagFloat write FTagFloat;
property TagStringstring read FTagString write FTagString


The following are discussed in the sections TStyledControl, Styles and Creating Custom Controls.

//Finds an object from the style via it's StyleName property.
function FindStyleResource(const AStyleLookupstring): TFmxObjectvirtual;
//Trigger animations and effects defined in the style
procedure StartAnimation(const ANamestring); virtual;
procedure StopAnimation(const ANamestring); virtual;
procedure StartTriggerAnimation(const AInstanceTFmxObject; const ATriggerstring); virtual;
procedure StartTriggerAnimationWait(const AInstanceTFmxObject; const ATriggerstring); virtual;
procedure StopTriggerAnimation(const AInstanceTFmxObject; const ATriggerstring); virtual;
procedure ApplyTriggerEffect(const AInstanceTFmxObject; const ATriggerstring); virtual;
    property StyleName
string read FStyleName write SetStyleName

Touch and Gestures

procedure CMGesture(var EventInfoTGestureEventInfo);
property TouchTTouchManager read FTouchManager write SetTouchManager;
property OnGestureTGestureEvent read FOnGesture write FOnGesture

Other Members

procedure AddFreeNotify(const AObjectIFreeNotification);
procedure RemoveFreeNotify(const AObjectIFreeNotification);
procedure GetTabOrderList(const List: TInterfaceListAChildrenBoolean); virtual;
property ActionClientboolean read FActionClient;
property DataTValue read GetData write SetData;
//If true the object will be saved in the form's FMX file. Set to false for objects created
   //by code at design time
property StoredBoolean read FStored write SetStored;

Version: XE4


div title=