Great! Thank you very much.
Now the program at least doesn't crash. It still doesn't quite work as it should, but I'll get there.
Great! Thank you very much.
Now the program at least doesn't crash. It still doesn't quite work as it should, but I'll get there.
You welcome, the natural way to instantiate, use and release a class, is like this
As you can see, I didn't declare a free destructor, it is implicitly inherited from tobject class. If you want to inherite some other class you must specify it when creating it, like this:Code:type tmyclass = class public constructor create; end; var myclass: tmyclass; begin myclass:= tmyclass.create; // // some processing... // myclass.free; end.
constructor and destructor are methods, just like any procedure, but have a fancy name and special purpouse. Inside them you must put your initialization and finalization code for the class. Of course you can inherite your own classes.Code:type tmyclass = class(tcomponent) public constructor create; end;
Hope this bring you some light. Happy codding!
Last edited by pitfiend; 22-03-2014 at 07:59 PM.
Thanks again. The program is working now, but now I'm trying to implement the input handeling and FPC acts up again.
The code is the following:
and the part in the game loop:Code:pressedkeys_: array of boolean; [...] procedure input.keydownevent(event:psdl_event); begin pressedkeys_[event^.key.keysym.scancode] := true; end; [...] function input.waskeypressed(key:psdl_keycode): boolean; var event: integer; begin event := key^.keysym.sym; waskeypressed := pressedkeys_[event]; end;
The "event := key^.keysym.sym;" part in input.waskeypressed gives me "Error: Illegal qualifier". It's probably a very trivial mistake on my part, but I can't really figure it out on my own.Code:while sdl_pollevent(@e) <> 0 do begin case e^.type_ of sdl_keydown: input_.keydownEvent(e); end; if input_.waskeypressed(e) = sdlk_escape then running := false; end;
Thanks again in advance for any help.
The most likely problem is that you are trying to acces elements from dynamic array with no pre set lenght which means it has the lenght of 0 elements. In Delphi this would result in "Out of bonds" error but I'm not sure what error FPC would create.
Anywhay instead of trying to duplicate C++ method of imput hndling why don't you use one from Pascal based SDL demos.
It is not always good to directly translate source code from one programming language to another becouse not all programming languages alow using same aproaches.
Thanks for your answer. I took a quick look at how hedgewars handles its input. Unfortunately, even if I set the array to [0..65536], like they do in hedgewars, the error message remains the same.
Last edited by much.love; 24-03-2014 at 12:13 AM.
array size should depend on enum range
and if key^.keysym.sym is an integer enum or sth then you can typecast it like this: event := integer(key^.keysym.sym);
Bookmarks