[fpc-pascal]Using UInt32 {LongWords} as Indexes for Properties.

Peter Vreman peter at freepascal.org
Wed Apr 7 08:25:43 CEST 2004


> To give a better picture of my problem:
>
> Type
>   tQSDL_Surface
>     = Class (SomeClass)
>       Protected
>         fFlags : UInt32; {LongWord}
>
>         Function GetFlag(aBit: UInt32): Boolean;
>         Function SetFlag(aBig: UInt32; aBool: Boolean);
>
>       Public
>         Constructor Create();
>         Destructor  Destroy();
>
>         Property    HWSurface : Boolean Index SDL_HWSurface
> 	    Read     GetFlag
>             Write   SetFlag;
>         Property    SRCAlpha  : Boolean Index SDL_SrcAlpha
>             Read    GetFlag
>             Write   SetFlag;
>       end;
>
> SDL_HWSurface and SDL_SRCAlpha are constants defined in the SDL_Video
> unit.  They are meant for Boolean operations.  More specificly they are
> meant to be ORed togeather to create a flag list and ANDed with fFlags
> to check for there state.
>
> I'm trying to do two things with these properties:
> 1# Not force a programmer to include the SDL Unit to get these
> constants.
> 2# Improve the readability of my code by using these properties to
> control flags.
>
> For instance a child object, SDL_VideoSurface, would have extra flags
> such as FullScreen.  Calling the following:
>
> MyVideoSurface.FullScreen := TRUE;
>
> would cause the fullscreen bit to be set to true and when the screen is
> allocated it will fill the entire screen.  The Problem is that if I
> define a constant index {$Mode ObjFPC} requires that index to be an
> Signed Integer value which it cannot be because that would change its
> binary value and the bitwise operations would be based on the wrong
> values.
>
> My solution is to simply create methods for each flag individualy that
> calls GetFlag/SetFlag with the correct paramaters.  I was just wondering
> if there was a way to get around this.
>
> If not, thanks anyways.  I just learned something new about indexes and
> and making sure I understand there limitation correctly.

Indexes are forced to 32bit signed, because the index type is not know yet
when the index keyword is parsed.

But i don't see any problems with 32bit signed/unsigned wrt bitwise
operations. The only problem can be range checking.

Which compiler version do you use? If it doesn't work with 1.9.x then
submit a bug with a complete example.

Peter






More information about the fpc-pascal mailing list