[fpc-devel] property writer can not use baseclass

Martin lazarus at mfriebe.de
Sat Oct 16 20:44:14 CEST 2010


  Is there a reason for this:

class TBase
   FBar: TObject;
end;

class TChild(TBase)
   function GetBar: TChildObject; // does just a typecast

   // provide a property Bar to avoid type-casts
   property Bar: TChildObject
     read GetBar
     write FBar; // this doesn't work
end;


I understand there is a rule for property and variable type to match 
exactly...

But in the above case that rule would not be needed?
Since FBar: TOBject is a base class of TChildObject, it can store any 
object that can be assigned to Bar.

Martin



More information about the fpc-devel mailing list