Blob Blame Raw
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Shape1: TShape;
    Timer1: TTimer;
    Timer2: TTimer;
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
      );
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  mouseX, mouseY: integer;

implementation

{$R *.lfm}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  mouseX := X;
  mouseY := Y;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Shape1.Left + Shape1.Width div 2 < mouseX then Shape1.Left := Shape1.Left + 5;
  if Shape1.Left + Shape1.Width div 2 > mouseX then Shape1.Left := Shape1.Left - 5;
  if Shape1.Top + Shape1.Height div 2 < mouseY then Shape1.Top := Shape1.Top + 5;
  if Shape1.Top + Shape1.Height div 2 > mouseY then Shape1.Top := Shape1.Top - 5;
end;

procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Beep;
  Shape1.Brush.Color := clRed;
  Cursor := crNone;
  Timer2.Enabled := true;
  Timer1.Enabled := false;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  Cursor := crDefault;
  Shape1.Brush.Color := clWhite;
  Timer1.Enabled := true;
  Timer2.Enabled := false;
end;

end.