However, below I have provided a simple demo of using the TAnimateFloat effect as well. Unlike Embarcadero’s examples, this demo utilizes TFloatAnimation at runtime to make a “Hello World” Splash screen from a TPanel.
Start by creating two controls (pnl: TPanel & lbl: TLabel) in the main form’s class.
TForm1 = class(TForm)
Panel1: TPanel;
FloatAnimation1: TFloatAnimation;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
pnl: TPanel;
lbl: TLabel;
public
{ Public declarations }
procedure DoClick(Sender: TObject);
end;
Add the following code to the form’s OnActivate and OnCreate events.
procedure TfrmMain.FormActivate(Sender: TObject);
begin
pnl.AnimateFloat('Position.y', Self.Height div 4, 1.0);
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
//create the panel
pnl:= TPanel.Create(self); pnl.Parent:= self;
pnl.Width:= ClientWidth div 2;
pnl.Height:= ClientHeight div 4;
pnl.Position.X:= (ClientWidth div 2) -(trunc(pnl.Width) div 2);
pnl.Position.Y:= - pnl.Height;
pnl.OnClick:= DoClick;
//create the label
lbl:= TLabel.Create(pnl);
lbl.Parent:= pnl;
lbl.Text:= 'Hello World';
lbl.TextAlign:= TTextAlign.taCenter;
lbl.Align:= TAlignLayout.alClient;
end;
In order to make the Panel reverse directions and go the other way, we will add an OnClick event for the TPanel created at runtime.
procedure TfrmMain.DoClick(Sender: TObject);
begin
pnl.AnimateFloat('Position.y', - pnl.Height, 1.0);
end;
Head over and see the other properties of TAnimateFloat.