[fpc-devel] -CR (method checking) and casting of classes
lazarus at mfriebe.de
Sun Aug 2 04:17:56 CEST 2009
I am wondering if the code below is valid or not.
It executes, but compiled with -CR gives a runtime error in fpc_check_object
xfoo is a variable to store a class of TFooClass, or any inherited
class. It is initialized with the inherited class TBar.
However casting tothe class of TBar (using TBarClass) causes an error?
In the below example, of course casting wasn't needed.
But if "var xfoo : TFooBaseClass" and TFooBaseClass did not have "hello"
then casting was needed (as soon as you knew, it was at least TFoo or
uses Classes, sysutils;
TFoo = Class
class procedure hello; virtual;
TFooClass = Class of TFoo;
TBar = class(TFoo)
class procedure hello; override;
TBarClass = Class of TBar;
class procedure TFoo.hello;
class procedure TBar.hello;
Var xfoo: TFooClass;
xfoo := tfoo;
More information about the fpc-devel