unit pasTAnimate;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, System.ComponentModel;

type
  TForm1 = class(TForm)
    Animate1: TAnimate;
    play: TButton;
    stop: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Estartframe: TEdit;
    Estopframe: TEdit;
    Esumframe: TEdit;
    Erepeatframe: TEdit;
    procedure Animate1Open(Sender: TObject);
    procedure playClick(Sender: TObject);
    procedure stopClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  StartFrame,StopFrame,RepeatFrame,SumFrame:integer;
implementation

{$R *.dfm}

procedure TForm1.Animate1Open(Sender: TObject);
begin
ShowMessage('TAnimaet组件触发OnOpen事件，初始化变量!');
StartFrame:=Animate1.StartFrame;
StopFrame:=Animate1.StopFrame;
RepeatFrame:=Animate1.Repetitions;
SumFrame:=Animate1.FrameCount;
Estartframe.Text:=IntToStr(StartFrame);
Estopframe.Text:=IntToStr(StopFrame);
Esumframe.Text:=IntToStr(SumFrame);
Erepeatframe.Text:=IntToStr(RepeatFrame);
end;
procedure TForm1.playClick(Sender: TObject);
begin
StartFrame:=StrToInt(Estartframe.text);
StopFrame:=StrToInt(Estopframe.text);
RepeatFrame:=StrToInt(Erepeatframe.text);
IF (StartFrame>StopFrame) or(StopFrame>SumFrame) then
  begin  //输入范围错误
    ShowMessage('输入帧的范围错误，所有设置复位！');
    Animate1.StartFrame:=1;
    Animate1.StopFrame:=Animate1.FrameCount;
    Animate1.Repetitions:=0;
    Estartframe.Text:='1';
    Estopframe.Text:=IntToStr(Animate1.FrameCount);
    Erepeatframe.Text:='0';
  end
else
  begin
   //设置组件的Enabled属性
   play.Enabled:=False;
   stop.Enabled:=True;
   Estartframe.Enabled:=False;
   Estopframe.Enabled:=False;
   Erepeatframe.Enabled:=False;
   // 设置TAnimate组件的属性，然后进行播放
   Animate1.StartFrame:=StartFrame;
   Animate1.StopFrame:=StopFrame;
   Animate1.Repetitions:=RepeatFrame;
   Animate1.Active:=True;  //进入播放状态
   end;
end;

procedure TForm1.stopClick(Sender: TObject);
begin
Animate1.Stop;
play.Enabled:=True;
stop.Enabled:=False;
Estartframe.Enabled:=True;
Estopframe.Enabled:=True;
Erepeatframe.Enabled:=True;
end;

end.
