[Lazarus] object type: strange behaviour
Graeme Geldenhuys
graemeg.lists at gmail.com
Mon Oct 25 09:12:43 CEST 2010
Op 2010-10-22 21:55, Hans-Peter Diettrich het geskryf:
>
> Delphi Objects should only be used with TP7 member types.
...snip...
> Note that Object types with no ancestors
> are properly initialized and finalized...
Thanks, I didn't know about the bug you mention. Luckily for me, when I
need a hierarchy I always use Classes, but for a single type that will
never have descendants, I often use Objects with member methods.
Here are two examples of Object usage in fpGUI:
type
TfpgRect = object // not class for static allocations
Top: TfpgCoord; // TfpgCoord is an alias for Integer
Left: TfpgCoord;
Width: TfpgCoord;
Height: TfpgCoord;
procedure SetRect(aleft, atop, awidth, aheight: TfpgCoord);
function Bottom: TfpgCoord;
function Right: TfpgCoord;
procedure SetBottom(Value: TfpgCoord);
procedure SetRight(Value: TfpgCoord);
end;
TfpgPoint = object // not class for static allocations
X: integer;
Y: integer;
procedure SetPoint(AX, AY: integer);
function ManhattanLength: integer;
function ManhattanLength(const PointB: TfpgPoint): integer;
end;
And because an instance can be allocated without a constructor, and
automatically free'ed, Object is really useful.
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net:8080/fpgui/
More information about the Lazarus
mailing list