FMXTFmxObjectAnimateFloat (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to call the FMX.Types.TFmxObject method FMX.Types.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. The 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 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 rectangle's color to the original state.

TBaseObjectAnimateFloat2.JPG

Code

//Delphi

procedure TForm3.TurnOpaqueClick(Sender: TObject);
begin
  Rectangle1.AnimateFloat('Opacity', 1.0, 5, TAnimationType.InOut,
    TInterpolationType.Linear);
end;

procedure TForm3.TurnTranslucentClick(Sender: TObject);
begin
  Rectangle1.AnimateFloat('Opacity', 0, 5, TAnimationType.InOut,
    TInterpolationType.Linear);
end;

Uses

See Also