یونیت 1 رو به این شکل در بیارش
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg, StdCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Image1: TImage;
Timer1: TTimer;
Edit1: TEdit;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
X:integer;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=38 then
image1.Top :=image1.Top-2;
if key=40 then
image1.Top :=image1.Top+2;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
shape1.Left :=shape1.Left +5;
if(shape1.Left>=image1.Left )then
begin
if(shape1.Left >= image1.Left )
and (shape1.Top >= image1.Top)
and (shape1.Top+Shape1.Height <= image1.Top+Image1.Height)
then
X:=x+10
else
X:=x-10;
edit1.Text :=inttostr(x);
shape1.Left :=0;
randomize;
shape1.Top :=random(Height-Shape1.Height);
end;
end;
end.