[fpc-pascal] Cast, inheritance, etc

silvioprog silvioprog at gmail.com
Tue Dec 4 22:35:01 CET 2012


2012/12/4 Marcos Douglas <md at delfire.net>

> On Tue, Dec 4, 2012 at 4:53 PM, Sven Barth <pascaldragon at googlemail.com>
> wrote:
> > On 04.12.2012 20:03, Marcos Douglas wrote:
> >>
> >> Hi,
> >>
> >> See the code below.
> >> My question is: Why the cast worked, considering the c variable is a
> >> TAClass instance, not a TBClass.
> >
> >
> > As long as you don't access fields of TBClass inside of GetInfoA you
> won't
> > run into problems, because FInfoA is accessed using an offset. If you
> want
> > to catch such problems you should compile with "-CR". The output will
> then
> > look like the following:
> >
> > === output begin ===
> >
> > An unhandled exception occurred at $080482E8 :
> > EInvalidCast : Invalid type cast
> >   $080482E8
> >
> > === output end ===
> >
> > As a sidenote: as long as you don't access an object member at all you'd
> > even be able to cast a primitive type like Integer to an object and call
> > methods on it... (not that I'd suggest to do this... ;) )
> >
> > Regards,
> > Sven
>
> Excellent explanation, thank you.
>
> Marcos Douglas


This is witchcraft! :)

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20121204/69d946e6/attachment.html>


More information about the fpc-pascal mailing list