[fpc-devel] .NET Reflection vs RTTI

Thorsten Engler thorsten.engler at gmx.net
Tue Nov 20 10:52:38 CET 2007


> Easy: look up the method in RTTI - you'll get the address.
> Push all arguments on the stack (see Remobjects/Innerfuse 
> PascalScript on how to do this, you need some assembler for 
> it), and return result value.
> 
> 2 days, tops. 

You are funny.

First, the RTTI can only give you the address of published methods. And
then, have you actually ever looked at PascalScript?? What do you think why
PSUnitImporter.exe is needed to parse all units that contain types which you
want to access from PascalScript and build import units which build up all
the additional type information that's missing in RTTI and create wrapper
code to make this work?

Have you ever tried to write the code that's required to dynamically call a
method given reasonable complete type information? I have and it's not
exactly trivial. 

>From the lack of anything compareable to InvokeRegistry in the FPC RTL
source I assume that FPC currently doesn't implement interface RTTI which is
the closest Delphi comes to actually offering usable RTTI for implementing
something like MethodInfo.Invoke. But even in that case where you DO have
PTypeInfo references for the params and result value and you know the
correct calling convention you are severly restricted by the general
limitations of RTTI, no usable info for record parameters, static arrays,
open arrays or pointers of any type. Also, the Delphi compiler is broken
when it comes to forward declared types so that you won't get any usable
type information if you have 2 interfaces which use each other in their
members so that you have to forward declare on of them.

Even ignoring custom attributes there are at a guess at least a couple of
weeks work on the compiler and RTL between what Delphi/FPC currently offer
and anything that comes even close to what the .NET reflection API currently
does. 

I'm not saying any of this is impossible, but it's a far cry from the
"single day" or "2 days, tops" you are talking about. And especially
implementing and maintaining something like a dynamic invoke for all
supported platforms is a huge undertaking. 

Cheers,
Thorsten







More information about the fpc-devel mailing list