cheesemunger
Programmer
- Jul 6, 2007
- 11
Ok i have done some code but it does not work..... why?
Here is the code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Tank: TImage;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
// Let's move the Tank every time the arrow keys are pressed
if Key = vk_left then Tank.Left := Tank.Left - 1; // Left
if Key = vk_up then Tank.Top := Tank.Top - 1; // Up
if Key = vk_right then Tank.Left := Tank.Left + 1; // Right
if Key = vk_down then Tank.Top := Tank.Top + 1; // Down
end;
end.
Here is the code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Tank: TImage;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
// Let's move the Tank every time the arrow keys are pressed
if Key = vk_left then Tank.Left := Tank.Left - 1; // Left
if Key = vk_up then Tank.Top := Tank.Top - 1; // Up
if Key = vk_right then Tank.Left := Tank.Left + 1; // Right
if Key = vk_down then Tank.Top := Tank.Top + 1; // Down
end;
end.