FMXTFmxObjectAnimateFloat (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to call the FMX.Types.TFmxObject method AnimateFloat. Note that, once called, you do not have access to the FMX.Ani.TFloatAnimation instance that FMX.Types.AnimateFloat creates.

This example requires a Multi-Device Application with a FMX.Objects.TRectangle and two FMX.StdCtrls.TButton objects in the FMX.Forms.TForm. FMX.Ani.TFloatAnimation is created dynamically.

The FMX.Ani.TFloatAnimation instance has the Rectangle1 as its parent, therefore it is cleaned up when Rectangle1 is deleted.

Note that the APropertyName parameter has to be a string that is a numerical property of Rectangle1, the class instance.

To replicate this example, use the Object Inspector to change the name of the buttons to TurnTranslucent and TurnOpaque. Create the event handlers for the FMX.Types.OnClick event of the buttons and copy the code below.

The form should look like the following image:

TBaseObjectAnimateFloat1.JPG

After pressing the TurnTranslucent button, the color of the rectangle starts to fade like in the following image, until the rectangle becomes transparent. Pressing TurnOpaque turns the color of the rectangle to the original state.

TBaseObjectAnimateFloat2.JPG

Code

//C++

void __fastcall TForm2::TurnTranslucentClick(TObject *Sender) {
	Rectangle1->AnimateFloat("Opacity", 0, 5, TAnimationType::InOut,
		TInterpolationType::Linear);
}
// ---------------------------------------------------------------------------

void __fastcall TForm2::TurnOpaqueClick(TObject *Sender) {
	Rectangle1->AnimateFloat("Opacity", 1.0, 5, TAnimationType::InOut,
		TInterpolationType::Linear);
}
// ---------------------------------------------------------------------------

Uses

See Also

Samples