Results 1 to 8 of 8

Thread: array type required (Jedi SDL and FPC)

  1. #1

    array type required (Jedi SDL and FPC)

    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.

  2. #2

    array type required (Jedi SDL and FPC)

    Try the following

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

    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)
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #3

    array type required (Jedi SDL and FPC)

    Quote Originally Posted by technomage
    Try the following

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

    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??

  4. #4

    array type required (Jedi SDL and FPC)

    [pascal]type
    PUint8array = ^TUint8array;
    TUint8array = array[0..MaxInt div SizeOf(Uint - 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;
    .....
    [/pascal]

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


    -MDelphi is it the same as putting {$MODE DEPHI} at the beginning of the program??
    Yes
    There are only 10 types of people in this world; those who understand binary and those who don't.

  5. #5

    array type required (Jedi SDL and FPC)

    thanks the second one worked (didnt test the first one)

  6. #6

    array type required (Jedi SDL and FPC)

    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.

  7. #7

    array type required (Jedi SDL and FPC)

    You need to use either the Round function or the Trunc function to make the conversion.

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

    or

    [pascal]
    MyRect.x := Trunc(x); // where x is your real variable
    [/pascal]
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  8. #8

    array type required (Jedi SDL and FPC)

    Just to add to the Keystate problem here is the code I use that works under Delphi and FreePascal (in {$MODE DELPHI} )

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

    PKeyStateArr is declared in sdl.pas.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •