bncthrd.pas

来自「关于利用DELPHI来进行企业级方案解决的著作的附书源码」· PAS 代码 · 共 54 行

PAS
54
字号
unit BncThrd;

interface

uses  WinProcs,Classes,Graphics,ExtCtrls;

type
  TBounceThread=class(TThread)
  private
       FShape:TShape;
       FXSpeed:Integer;
       FYSpeed:Integer;
       procedure MoveShape;
  protected
       procedure Execute;override;
  public
       constructor Create(Suspended:Boolean;Shape:TShape;XSpeed,YSpeed:Integer);
       property Shape:TShape read FShape;
  end;

implementation

procedure TBounceThread.MoveShape;
//var  MaxHeight,MaxWidth:Integer;
begin
    with Fshape do begin
    Left:=Left+FXSpeed;
    Top:=Top+FYSpeed;
    if(Left<0)or(Left+Width>Parent.Width)then
     FXSpeed:=FXSpeed*-1;
    if(Top<0)or(Top+Height>Parent.Height)then
     FYSpeed:=FYSpeed*-1;
end;
end;

procedure  TBounceThread.Execute;
begin
    While  not Terminated  do
    begin
         Synchronize(MoveShape);
    end;
end;

constructor TBounceThread.Create(Suspended:Boolean;Shape:TShape;XSpeed,YSpeed:Integer);
begin
     inherited Create(Suspended);
     FShape:=Shape;
     FXSpeed:=XSpeed;{X轴走向的速度}
     FYSpeed:=YSpeed;{Y轴走向的速度}
     FreeOnTerminate:=True;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?