Vytvořila jsem objekt TObrazek, který bych ráda posouvala po ploše Image1 pomocí šipek na klávesnici. Když však spustím program, zobrazí se mi níže uvedená chybová zpráva: Error: identifier idents no member “Left“… Error: identifier idents no member “Top“… Můžete mi vysvětlit, co přesně to hlášení znamená a jak chybu opravit.
Fórum › Pascal
Error: identifier idents no member 'left'

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key=VK_LEFT then TObrazek.Left:=TObrazek.Left-1;
if Key=VK_RIGHT then TObrazek.Left:=TObrazek.Left+1;
if Key=VK_UP then TObrazek.Top:=TObrazek.Top-1;
if Key=VK_DOWN then TObrazek.Top:=TObrazek.Top+1;
end;
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
const vk_Left=37;
vk_Right=39;
vk_Up=38;
vk_Down=40;
type
TObrazek = class
obr: TBitmap;
c: TCanvas;
constructor Create(cc: TCanvas);
procedure Kresli;
destructor Destroy; override;
end;
{ TForm1 }
var o: TObrazek;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
o.Kresli;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
o:=TObrazek.Create(Image1.Canvas); o.Kresli;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
if Key=VK_LEFT then TObrazek.Left:=TObrazek.Left-1;
if Key=VK_RIGHT then TObrazek.Left:=TObrazek.Left+1;
if Key=VK_UP then TObrazek.Top:=TObrazek.Top-1;
if Key=VK_DOWN then TObrazek.Top:=TObrazek.Top+1;
end;
constructor TObrazek.Create(cc: TCanvas);
begin
c:=cc;
obr:=TBitmap.Create;
obr.LoadFromFile('obrazek.bmp');
obr.Transparent:=true;
end;
procedure TObrazek.Kresli;
begin
c.Draw(0, 0, obr);
end;
destructor TObrazek.Destroy;
begin
obr.Free;
end;
end.
TObrazek je jen datovy typ... pracovat musis s promennou... jestli sem postrehl spravne tak je to "o" (a to jeste mozna ne primo left/top ale pres ten parametr obr...)
Ok, tak potom si dej na form 2 x TImage. Jeden pro pozadí (pojmenuj ho třeba imgBackground) a jeden pro postavičku (pojmenuj ho třeba imgFigure).
Pohyb pak můžeš simulovat změnou souřadnic přes vlastnosti imgFigure.
Pohyb vlevo:
imgFigure.Left := imgFigure.Left - 5;
Pohyb vpravo:
imgFigure.Left := imgFigure.Left + 5;
atd...
Obrázky do těch TImage by mělo jít nahrát přes vlastnost Picture. (Aspoň tak se to jmenuje v Delphi, v Lazarusu to bude nejspíš stejné, nemám ho momentálně k dispozici.)

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Error C2439: member could not be initialized — založil Sarge
Error C2065: undeclared identifier — založil Sarge
Error C3861: 'strcomp': identifier not found — založil Tundra
Alternativa k left join? — založil VelkyBubak
Složitější LEFT JOIN — založil David Plšek
Moderátoři diskuze