PDA

View Full Version : array type required (Jedi SDL and FPC)



antonmaster
04-09-2006, 06:30 PM
Hi. Im compiling a prog using jedi-sdl and compiling it with freepascal.
this is the code:

keystate : PUint8;
begin
keystate := SDL_GetKeystate(nil);
SDL_PumpEvents();

if (keystate[SDLK_q] <> 0) then { error here: array type required}
exit;
.....
....

but it doesnt compile. The compiler tells this:
Array type required.

In C it was so easy as this, but in Pascal it doesnt work.
Thanks for any help.

technomage
04-09-2006, 06:33 PM
Try the following


if (keystate^[SDLK_q] <> 0) then


You need to dereference the pointer in freepascal unless you use -MDelphi in which case you don't need the ^ (but it doesn't hurt)

antonmaster
04-09-2006, 06:44 PM
Try the following


if (keystate^[SDLK_q] <> 0) then


You need to dereference the pointer in freepascal unless you use -MDelphi in which case you don't need the ^ (but it doesn't hurt)

I added ^ but now it tells: Illegal qualifier.
-MDelphi is it the same as putting {$MODE DEPHI} at the beginning of the program??

Clootie
04-09-2006, 08:14 PM
type
PUint8array = ^TUint8array;
TUint8array = array[0..MaxInt div SizeOf(Uint8) - 1] of Uint8;
var
keystate : PUint8array; // PUint8;
begin
keystate := SDL_GetKeystate(nil);
SDL_PumpEvents();

if (keystate[SDLK_q] <> 0) then { error here: array type required}
exit;
.....


if this will not work (I have not checked), then try this:
var
keystate : PUint8;
...
if (PUint8array(keystate)[SDLK_q] <> 0) then
...




-MDelphi is it the same as putting {$MODE DEPHI} at the beginning of the program??Yes

antonmaster
04-09-2006, 11:15 PM
thanks the second one worked (didnt test the first one)

antonmaster
05-09-2006, 09:37 PM
another question about types:

I need to have a variable x and y of real type, but when setting SDL_Rect I have to use a smallint type, so I have to convert x and y vars of type real to type smallint. If I just write this:
smallint(x);
The compiler shows that its an illegal conversion. Is there any way to convert it??

Thanks.

technomage
05-09-2006, 10:36 PM
You need to use either the Round function or the Trunc function to make the conversion.


MyRect.x := Round(x); // where x is your real variable


or


MyRect.x := Trunc(x); // where x is your real variable

technomage
05-09-2006, 10:45 PM
Just to add to the Keystate problem here is the code I use that works under Delphi and FreePascal (in {$MODE DELPHI} )


var keyState: PKeyStateArr;
begin
keyState := PKeyStateArr(SDL_GetKeyState(nil));
if(keyState[SDLK_ESC]=SDL_PRESSED) then
begin
Exit;
end;


PKeyStateArr is declared in sdl.pas.