Daniel Ashan Posted November 15, 2010 Report Share Posted November 15, 2010 Mam pytanie móglby mi ktoś opisać w jaki sposób przypisuje się zmienną do danego obiektu np. obrazka. Link to comment Share on other sites More sharing options...
xevil21 Posted November 15, 2010 Report Share Posted November 15, 2010 Witam. Poczytaj np: http://4programmers.net/Delphi/Record Pozdrawiam! Link to comment Share on other sites More sharing options...
Daniel Ashan Posted November 15, 2010 Author Report Share Posted November 15, 2010 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 More sharing options...
Adam27 Posted November 15, 2010 Report Share Posted November 15, 2010 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 More sharing options...
Daniel Ashan Posted November 15, 2010 Author Report Share Posted November 15, 2010 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 More sharing options...
Adam27 Posted November 15, 2010 Report Share Posted November 15, 2010 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 More sharing options...
Daniel Ashan Posted November 15, 2010 Author Report Share Posted November 15, 2010 Chyba jestem za głupi na programowanie Chodzi mi o to że mam zmienną x o wartości 100. Po naciśnieciu spacji zmienna x powinna zmienjszyć się o 20, a następnie gdy osiągnie 0 Shape powienien się przesunąć. Link to comment Share on other sites More sharing options...
Adam27 Posted November 15, 2010 Report Share Posted November 15, 2010 W kodzie zmniejszasz Kwadrat.x, a to zupełnie co innego. Ale nawet gdybyś to zmienił, to i tak po każdym naciśnięciu klawisza x by wracało do wartości 100 dzięki linijce x:=100; Etharnion - 2D RPG Szukam grafika chętnego do współpracy przy projekcie. Link to comment Share on other sites More sharing options...
Daniel Ashan Posted November 15, 2010 Author Report Share Posted November 15, 2010 Więc co mam z tym zrobić? Spróbować pętlą czy da się to rozwiązać jakoś inaczej? Link to comment Share on other sites More sharing options...
Adam27 Posted November 15, 2010 Report Share Posted November 15, 2010 Po pierwsze nie potrzebujesz tutaj rekordu. Po drugie zmień tą linijkę: if Key = VK_SPACE then x := x-20; I po trzecie zadeklaruj x jako zmienną globalną i na początku programu przypisz do niej wartość 100; Etharnion - 2D RPG Szukam grafika chętnego do współpracy przy projekcie. Link to comment Share on other sites More sharing options...
Daniel Ashan Posted November 15, 2010 Author Report Share Posted November 15, 2010 Wielkie dzięki za pomoc Adam, jak cię kiedyś spotkam masz ode mnie piwo . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.