Jump to content

[Delphi] Zmienna opisująca obiekt np. obrazek


Daniel Ashan

Recommended Posts

Mniej więcej zrozumiałem o co chodzi. Niestety przy kompilacji wyskakuje błąd :

 rocedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
 );
 var
 x : integer;
 type
 Kwadrat = record
   x : integer;
   end;


begin
 If Key = VK_UP then Image1.Top := Image1.Top - 15;
 If Key = VK_UP then Image1.Picture.LoadFromFile ('Ludzik1up.png');
 If Key = VK_DOWN then Image1.Top := Image1.Top + 15;
 If Key = VK_DOWN then Image1.Picture.LoadFromFile ('Ludzik1down.png');
 If Key = VK_LEFT then Image1.Left := Image1.Left - 15;
 If Key = VK_LEFT then Image1.Picture.LoadFromFile ('Ludzik1left.png');
 If Key = VK_RIGHT then Image1.Left := Image1.Left + 15;
 If Key = VK_RIGHT then Image1.Picture.LoadFromFile ('Ludzik1right.png');
 x:= 100;
 IF Key = VK_SPACE then Kwadrat.x := Kwadrat.x - 20;
 IF x = 0 then Shape1.Left := Shape1.Left - 60;


end;                            

 

unit1.pas(58,26) Error: Variable identifier expected

Zaznacza : IF Key = VK_SPACE then Kwadrat.x := Kwadrat.x - 20;

 

I mam jeszcze pytanko

czy np zamiast Kwadrat mogę wstawić Shape1 lub Image1, Image2 i tak dalej?

 

Z góry dziękuje

Link to comment
Share on other sites

Zadeklarowałeś typ Kwadrat, a nie zmienną. Wygodnie jest zadeklarować typ jako TKwadrat (przyjęło się, że przed nazwą typu pisze się literę "T"), a potem trzeba jeszcze stworzyć zmienną np. Kwadrat, która będzie tego typu.

 

type TKwadrat = record X: Integer end;
var Kwadrat: TKwadrat;

 

czy np zamiast Kwadrat mogę wstawić Shape1 lub Image1, Image2 i tak dalej?

Napisz jaśniej.

Etharnion - 2D RPG

Szukam grafika chętnego do współpracy przy projekcie.

Link to comment
Share on other sites

Ok teraz program się kompiluje ale jest kolejny problem :

Odpalam program, naciskam spację kilka razy i nic. A według tego co napisałem w kodzie Shape1 powinien mi się przesunąć.

 

Chodziło mi o to że równie dobrze może być

 
type
TShape1 : record
x : integer;
end;

var
Shape1 : TShape1; 

Link to comment
Share on other sites

CYTATA według tego co napisałem w kodzie Shape1 powinien mi się przesunąć.

Jak naciśniesz spacje to zmienia się pole x rekordu Kwadrat, który nie ma nic wspólnego z Shape'em.

 

Chodziło mi o to że równie dobrze może być [...]

Jeżeli zmienisz jeden dwukropek na znak równości to tak. Jak nazwiesz typ albo zmienną generalnie nie ma znaczenia.

Etharnion - 2D RPG

Szukam grafika chętnego do współpracy przy projekcie.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...