[fpc-pascal]Using UInt32 {LongWords} as Indexes for Properties.
Jon D. Sawyer
badquanta6384 at comcast.net
Wed Apr 7 06:54:13 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.
More information about the fpc-pascal
mailing list