rtti

identifying the type

Hi, In my application, there is a inheritance hierarchy in which only the classes that are at the end of the inheritance chain are non-abstract classes. Also there is some usage of boost::variant. I want to write a function which takes a pointer and a Type and says whether the object belongs to that type. For example #define IsA(nod...

RTTI and Portability in C++

If a compiler doesn't "support" RTTI, does that mean that the compiler can not handle class hierarchies that have virtual functions in them? Or have I been misunderstanding the literature about how RTTI isn't portable, and the issues lie elsewhere? Thank you all for your comments! ...

C++ lib RTTI in C# application

I am developing game editor in C# that uses c++ lib files. I want RTTI for C++ classes in C#. Is it possible to get RTTI of C++ class in C#? If yes how? ...

Rtti for Variant Records

I try to write a kind of object/record serializer with Delphi 2010 and wonder if there is a way to detect, if a record is a variant record. E.g. the TRect record as defined in Types.pas: TRect = record case Integer of 0: (Left, Top, Right, Bottom: Longint); 1: (TopLeft, BottomRight: TPoint); end; As my serializer should work recu...

Rtti data manipulation and consistency in Delphi 2010

Has anyone an idea, how I can make TValue using a reference to the original data? In my serialization project, I use (as suggested in XML-Serialization) a generic serializer which stores TValues in an internal tree-structure (similar to the MemberMap in the example). This member-tree should also be used to create a dynamic setup form an...

Rtti accessing fields and properties in complex data structures

As already discussed in Rtti data manipulation and consistency in Delphi 2010 a consistency between the original data and rtti values can be reached by accessing members by using a pair of TRttiField and an instance pointer. This would be very easy in case of a simple class with only basic member types (like e.g. integers or strings). Bu...

Delphi Superobject, generic list to json

I have a object with some TObjectList<>-fields that I try to encode as JSON with help form SuperObject. TLogs = TObjectList<TLog>; TMyObject = class(TObject) private FLogs: TLogs; end; Deep inside SuperObjects code, there is a ToClass procedure, iterating the fields and add them to the json result. In this loop, there is a check on...

Can I get a PTypeInfo from a string?

This is probably going to be a "no", but is there any way I can use Delphi's RTTI, either old-school or the 2010 extended RTTI, to pass in a string containing the name of a type, specifically the name of an enumerated type, and have it give me the PTypeInfo for that type? I've looked through RTTI.pas and TypInfo.pas and I don't see any ...

Need to know about good C++ Reflection API (For RuntimeType Identification -RTTI and runtime calling)

Hello, I need to know about good C++ Reflection API(Would be better if Microsoft API is available) which enables me to determine the types(classes,structs,enums,ints,float,doubles...)identification at runtime, declaring them and finally to call methods on those types at run time too. Regards Usman ...

Type casting in C++ by detecting the current 'this' object type

My question is related to RTTI in C++ where I'm trying to check if an object belongs to the type hierarchy of another object. The BelongsTo() method checks this. I tried using typeid, but it throws an error and I'm not sure about any other way how I can find the target type to convert to at runtime. #include <iostream> #include <typein...

Mixing libraries with and without RTTI with GCC on Mac OS X?

I've been banging my head on an issue and before I continue injuring myself some more, I'd like to confirm: Is it possible to have a GCC project that uses libraries that are compiled with and without RTTI? So, for example, I have project A (compiled without RTTI) that uses library B (compiled with RTTI) and library C (compiled withou...

Delphi RTTI unable to find interface

I'm trying to fetch an interface using D2010 RTTI. program rtti_sb_1; {$APPTYPE CONSOLE} {$M+} uses SysUtils, Rtti, mynamespace in 'mynamespace.pas'; var ctx: TRttiContext; RType: TRttiType; MyClass: TMyIntfClass; begin ctx := TRttiContext.Create; MyClass := TMyIntfClass.Create; // This prints a list of all kn...

Delphi TRttiType.GetMethods return zero TRttiMethod instances

I've recently been able to fetch a TRttiType for an interface using TRttiContext.FindType using Robert Loves "GetType"-workaround ("registering" the interface by an explicit call to ctx.GetType, e.g. RType := ctx.GetType(TypeInfo(IMyPrettyLittleInterface));). One logical next step would be to iterate the methods of said interface. Consi...

Delphi interface cast using TValue

I've recently experimented extensively with interfaces and D2010 RTTI. I don't know at runtime the actual type of the interface; although I will have access to it's qualified name using a string. Consider the following: program rtti_sb_1; {$APPTYPE CONSOLE} uses SysUtils, Rtti, TypInfo, mynamespace in 'mynamespace.pas'; var ctx: ...

Okay to compare pointers returned by RUNTIME_CLASS() macro?

I've got a function that takes a list of CRuntimeClass pointers in order to setup a view. I'd like to return without doing anything if the function is called with a list of the same classes that are already setup. Saving the pointer values and comparing them on the next call is currently working, but I want to verify that that's a legal ...

Why doesn't C++ allow you to request a pointer to the most derived class?

(This question should probably be answered with a reference to Stroustrup.) It seems extremely useful to be able to request a pointer to the most derived class, as in the following: class Base { ... }; class DerivedA { ... }; class DerivedB { ... }; class Processor { public: void Do(Base* b) {...} void Do(DerivedA* d) {...} voi...

Enumerated types with specified values do not have TypeInfo, why?

Using Delphi 2007 I can write the following code: interface TTestType = (ttTest1, ttTest2); procedure enumName; var EnumName: String; begin EnumName := GetEnumName(TypeInfo(TTestType), Ord(ttTest1)); end; This compiles and works, EnumName contains 'ttTest1' at the end of the function. However, when I change my TTestType to somet...

How to create an instance of object with RTTI in Delphi 2010?

As we all known, when we call a constructor of a class like this: instance := TSomeClass.Create; The Delphi compiler actually do the following things: Call the static NewInstance method to allocate memory and initialize the memory layout. Call the constructor method to perform the initialization of the class Call the AfterConstructi...

Delphi 2010 RTTI and Pointer fields

I have problems in a following code: program Project4; {$APPTYPE CONSOLE} uses SysUtils, RTTI; type TRecord2 = record c: integer; d: integer; end; TClass1 = class public FRecord: record a: integer; b: integer; end; FRecord2: TRecord2; FPointRecord3: ^TRecord2; constructor Create; ...

Getting the string name of an interface using Delphi RTTI

I have proved that I can get the name of an interface from its GUID using Delphi 2010 (eg IMyInterface converted to the string 'IMyInterface'. I'd like to achieve this in Delphi 7 (for compatibility). Is this possible? Or are there fundamental compiler limitations. ...