PDA

View Full Version : Error: Illegal qualifier



WILL
22-04-2006, 08:19 PM
I get the strangest error when I try running my project with this code in it. Thing is this code works in another project, it should be code independant. What am I not seeing?

procedure DrawTile(GameScreen: PSDL_Surface; X, Y, TileIndex, TileSize: Integer; TileSet: PSDL_Surface);
var
SrcRect, DestRect: TSDL_Rect;
begin
SrcRect := SDLRect(TileIndex * TileSize, 0, TileSize, TileSize);
DestRect := SDLRect(X, Y, TileSize, TileSize);
if ((X < GameScreen.w) or (X > -TileSize)) and ((Y < GameScreen.h) or (Y > -TileSize)) then
SDL_BlitSurface(TileSet, @SrcRect, GameScreen, @DestRect);
end;

w and h are the Width and Height of the game screen.

Here are the error messages I'm getting:


NightStalker2.lpr(359,26) Error: Illegal qualifier
NightStalker2.lpr(359,26) Hint: may be pointer dereference is missing
NightStalker2.lpr(359,13) Error: Operation "<" not supported for types "LongInt" and "PSDL_Surface"
NightStalker2.lpr(359,26) Fatal: Syntax error, ")" expected but "identifier W" found


oh FYI...
if ((X < GameScreen.w) or (X > -TileSize)) and ((Y < GameScreen.h) or (Y > -TileSize)) then is line 359.

Srki_82
22-04-2006, 08:50 PM
Every thing look's ok... if you are not using {$mode Delphi} then you must write code like this:

if &#40;&#40;X < GameScreen^.w&#41; or &#40;X > -TileSize&#41;&#41; and &#40;&#40;Y < GameScreen^.h&#41; or &#40;Y > -TileSize&#41;&#41;

Maybe I'm wrong, but i think that FPC doesn't automaticly convert pointer types to non pointer types (PSDL_Surface to TSDL_Surface).

WILL
22-04-2006, 10:40 PM
Well thats a possibility. It was a Delphi program moved to Lazarus so it may have something to do with the errors.

The funniest thing though... I move this function form the main 'program' source to a unit and reference to it and all of a sudden, no errors. :?

Interesting...


Any ideas guys?

michalis
24-04-2006, 03:59 AM
Maybe I'm wrong, but i think that FPC doesn't automaticly convert pointer types to non pointer types (PSDL_Surface to TSDL_Surface).

You're 100% correct. In non-delphi modes you have to always explicitly dereference pointer.

Why ? The long story is, AFAIK: Because in non-delphi modes you get other feature: Assuming that PMyType is a pointer to TMyType, and you have variable like MyTypePtr (of type PMyType), you can write things like
MyTypePtr[100]
and it will be treated like MyTypePtr was a pointer to an array of TMyType structures. In Delphi (or in FPC in delphi mode) to do the same thing you would have to declare some dummy type that is a pointer to an "inifite" array, like
TMyTypeArray = array[0..MaxInt div SizeOf(TMyType)-1]of TMyType;
PTMyTypeArray = ^TTMyTypeArray;
and write
PTMyTypeArray(MyTypePtr)[100]

So in Delphi mode you get automatic dereferencing of pointers to arrays/records, and in non-delphi mode you get treating pointers as arrays (like in C). These two features together could in some cases produce ambiguous code, so you can get only one feature or the other, not both at once...



The funniest thing though... I move this function form the main 'program' source to a unit and reference to it and all of a sudden, no errors. Confused


Most probably you're accidentaly compiling your unit in delphi mode, and program file in non-delphi (like objfpc) mode. Maybe you include in your unit some file that does {$mode delphi} ? To hunt this down you can compile your code with -vc option ("Show conditionals"), look there for messages like
Macro defined: FPC_DELPHI
or
Macro defined: FPC_OBJFPC
These indicate FPC $mode changes.

WILL
24-04-2006, 06:25 AM
ah ha! Nice catch michalis. ;)

Found the culprit. {$mode objfpc}{$H+}

Lazarus likes sticking this at the start of every new unit and program it creates. I have overall Delphi compatability mode set under my project's compiler options, but obviously didn't even notice that this little line was in there.

Thanks for the help guys. Seems I've been spoiled by the way Delphi simplifies pointers.