Thema: Image bewegen

Einzelnen Beitrag anzeigen

Jonski

Registriert seit: 28. Nov 2009
Ort: Hessen
75 Beiträge
 
Delphi 7 Personal
 
#21

Re: Image bewegen

  Alt 28. Nov 2009, 23:21
Also ich habe folgendes Problem, dass Delphi sagt Undefinierter Bezeichner Image1 und so weiter und sofort:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);

var Bitmap:TBitmap;
begin
  Bitmap:=TBitmap.Create;
  try
    Bitmap.Width:=Image1.Width;
    Bitmap.Height:=Image1.Height;
    Bitmap.Canvas.pen.color:=clGreen;
    Bitmap.Canvas.pen.width:=10;
    Bitmap.Canvas.Ellipse(5,5,50,50);
    Image1.Picture.Assign(Bitmap);
  finally
    Bitmap.Free;
  end;

Bitmap:=TBitmap.Create;
  try
    Bitmap.Width:=Image2.Width;
    Bitmap.Height:=Image2.Height;
    Bitmap.Canvas.pen.color:=clBlue;
    Bitmap.Canvas.pen.width:=10;
    Bitmap.Canvas.Ellipse(5,5,50,50);
    Image1.Picture.Assign(Bitmap);
  finally
    Bitmap.Free;
  end;

  with Image1 do
  begin
  transparent:=true;
  end
end;

procedure FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
begin

if Image1.Left - 10 > Image2.Left then
  begin
  Image1.Left := Image1.Left - 10;
  end
else begin
  case Key of
    VK_LEFT: Image1.Left := Image1.Left - 10;
  end
end

if Image1.Left + 10 > Image2.Left then
  begin
  Image1.Left := Image1.Left + 10;
  end
else begin
  case Key of
    VK_RIGHT: Image1.Left := Image1.Left + 10;
  end
end

if Image1.Top - 10 > Image.Top then
  begin
  Image1.Top := Image1.Top - 10;
  end
else begin
  case Key of
    VK_DOWN: Image1.Top := Image1.Top - 10;
  end
end

if Image1.Top + 10 > Image2.Top then
  begin
  Image1.Top := Image1.Top + 10;
  end
else begin
  case Key of
    VK_UP: Image1.Top := Image1.Top + 10;
  end
end
end;

end.
Bitte helft mir.
Jonas
MFG Jonski
  Mit Zitat antworten Zitat