[fpc-pascal]How to obtain runtime type of class?

Jonas Maebe jonas at zeus.rug.ac.be
Tue Feb 25 13:05:01 CET 2003


On dinsdag, feb 25, 2003, at 15:01 Europe/Brussels, Anton Tichawa wrote:

> What object code is generated for this? I assume that, informally 
> speaking,
>
> Ord(TClassB) = Ord(@VMT)
>
> and that
>
> if x IS TClassB
>
> yields somthing like
>
> if @(x.VMT) = TClassB?
>
> Am I wrong here?

Yes, because "is" also returns true if the instance is of a type that 
inherits from tclassb. So the "is" operator is translated into a call 
to the following helper routine

     function fpc_do_is(aclass : tclass;aobject : tobject) : 
boolean;[public,alia
s: 'FPC_DO_IS']; {$ifdef hascompilerproc} compilerproc; {$endif}
       begin
          fpc_do_is:=assigned(aobject) and assigned(aclass) and
            aobject.inheritsfrom(aclass);
       end;


Jonas




More information about the fpc-pascal mailing list