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

Matt Emson memsom at interalpha.co.uk
Tue Apr 6 12:29:05 CEST 2004


> Property SWSurface : Boolean Index SDL_SWSurface
> Read GetFlags Write SetFlags;
>
> If I declare Get/Set Flags as the following:
> Function GetFlags(aBit: UInt32): Boolean;
> Procedure SetFlags(aBit: UInt32; aBool: Boolean);

Looks like you're tying to use an indexed property. Dunno what mode you're
using, but in Delphi mode:

unit Example;

interface

type

 t = class
 private
    FSurface: SDL_SWSurface;

    function GetSWSurfaceFlags(index: integer): Boolean;
    procedure SetSWSurfaceFlags(index: integer; const Value: Boolean);
 public
   property SWSurfaceFlags[index: integer] : Boolean read GetSWSurfaceFlags
write SetSWSurfaceFlags;
 end;

implementation

{ t }

function t.GetSWSurfaceFlags(index: integer): Boolean;
begin
  /// do stuff with FSurface
end;

procedure t.SetSWSurfaceFlags(index: integer; const Value: Boolean);
begin
  /// do stuff with FSurface
end;

end.


You would then implement the get/set by implementing read/writes to
SDL_SWSurface...

I would have thought that this is quite limiting though. I would also have
a:

property SWSurfaceColor[index: uint32] : TColor
  read GetSWSurfaceColor write SetSWSurfaceColor;


function t.GetSWSurfaceColor(index: uint32): TColor;

procedure t.SetSWSurfaceColor(index: uint32; const value: TColor);

The params are not me being pedantic, by the was, but the way in which
Delphi implements properties. Other FPC modes may be a little more
forgiving.

Hope that helps,

Matt







More information about the fpc-pascal mailing list