AutoAnimate example for Delphi

This example gets information about an animated file, uses the information to position the LEAD control, and plays the animation as it loads the file.

procedure TForm1.Button1Click(Sender: TObject);
var
  HeightFactor,WidthFactor: Integer;
  HeightAllowed,WidthAllowed: Integer;
begin
  { Force continued looping after the file loads. }
  Lead1.AutoAnimationLoop := AUTOANIMATIONLOOP_INFINITE
  Lead1.GetFileInfo('d:\ltwin11\images\eye.gif', 0); 
  { Exit if this is not an animated file. }
  if Lead1.InfoAnimation = False then
    ShowMessage('Not an animated file!!')
  else
   begin
     { Calculate information for centering the LEAD control. }
     {Set the variables used for preserving the aspect ratio. }
     {Allow for a border of 1/8 of the form size. }
     {The units of measure do not matter, since we are calculating proportions. }
     HeightFactor := round(Lead1.InfoHeight);
     WidthFactor := round(Lead1.InfoWidth);
     HeightAllowed := round(ClientHeight * 3/4);
     WidthAllowed := round(ClientWidth * 3/4); 
     { Center the LEAD control on the form, preserving the aspect ratio.
     Check to see if using the maximum width will make the image too tall.
     Set the dimensions based on the result. }
     If ((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed Then
      begin
        Lead1.Left := round(ClientWidth / 8);
        Lead1.Width := WidthAllowed;
        Lead1.Height := round((Lead1.Width * HeightFactor) / WidthFactor);
        Lead1.Top := round((ClientHeight - Lead1.Height) / 2);
      end
     else
      begin
        Lead1.Top := round(ClientHeight / 8);
        Lead1.Height := HeightAllowed;
        Lead1.Width := round((Lead1.Height * WidthFactor) / HeightFactor);
        Lead1.Left := round((ClientWidth - Lead1.Width) / 2);
      end; 
    { Set properties for playing the animation as is loads. }
    Lead1.AutoAnimate := True;
    Lead1.AutoRepaint := True; 
    { Load the animated file. }
    Lead1.Load('d:\ltwin11\images\eye.gif', 0, 0, -1);
  end;
end;