rtti

Why does dynamic cast from class to subclass requires the class to be polymorphic?

As I understand it, what makes dynamic cast different from a static cast is its use of RTTI, and the fact that it fails if the dynamic type of a variable- when casting from base to derived- does not fit. But why does the class have to be polymorphic for that to be done if we have the RTTI anyway? EDIT: Since there was some confusion abo...

How to get the object type from a collection (vector) of parent objects using RTTI

Hello, I have a base class which has two child classes derived from it. class A {}; class B : public A {}; class C : public A {}; I have another class that has a pointer to collection of class A members using a vector, something like this: vector<A*> *m_collection; And what I do is to create objects of class B or C and add them to...

Find all Class Helpers in Delphi at runtime using RTTI?

Does the extended RTTI in Delphi 2010 offer a way to list defined Class and Record Helpers at run time? As far as I know Delphi does not show a hint or warning when more than one class helper is defined for a class, class helper detection might be a helpful routine in 'quality assurance'. p.s. of course I know I should never ever use t...

Testing for Type Equality without RTTI

Say B and C are derived from A. I want to be able to test whether any two instances of classes derived from A are instances of the same class, that is, whether A* foo and A* bar both point to B instances, without using RTTI. My current solution is something like this: class A { protected: typedef uintptr_t Code; virtual Code co...

Anyone know how to use TValue.AsType<TNotifyEvent> properly?

I'm trying to use RTTI to add an event handler to a control, that may already have an event handler set. The code looks something like this: var prop: TRttiProperty; val: TValue; begin prop := FContext.GetType(MyControl.ClassInfo).GetProperty('OnChange'); val := prop.GetValue(MyControl); FOldOnChange := val.AsType<TNotifyEvent...

Emulating Dynamic Dispatch in C++ based on Template Parameters

This is heavily simplified for the sake of the question. Say I have a hierarchy: struct Base { virtual int precision() const = 0; }; template<int Precision> struct Derived : public Base { typedef Traits<Precision>::Type Type; Derived(Type data) : value(data) {} virtual int precision() const { return Precision; } ...

What is the general feeling about reflection extensions in std::type_info?

I've noticed that reflection is one feature that developers from other languages find very lacking in c++. For certain applications I can really see why! It is so much easier to write things like an IDE's auto-complete if you had reflection. And certainly serialization APIs would be a world easier if we had it. On the other side, one of...

Converting an string to a enum type using TValue?

I want to convert an string to an enum type using TValue, I googled but I didn't find how to do that. type TEnumTest = (etFirst, etSecond); var D: TEnumTest; begin D := StrToENumTest('etFirst'); end; function StrToEnumTest(pStr:String):TEnumTest; var V: TValue; begin V := TValue.From<String>(pstr); Result := V.AsType<TE...

Delphi - RTTI info about methods in records

hello, how to extract RTTI info about methods in Delphi records? is it possible by using new Rtti unit? ...

Delphi: RTTI for indexed properties in 2010?

Please forgive the verbosity of the following code example. Using Delphi 2009, I created the two classes TOtherClass and TMyClass: TOtherClass = class(TObject) public FData: string; end; TMyClass = class(TObject) private FIndxPropList: Array of TOtherClass; function GetIndxProp(Index: Integer): TOtherClass; procedure Se...

Delphi 2010: whatever happened to TRTTIConstructor?

I've got two questions (of which at least one is regarding RTTI in D2010 and dynamic instancing) I was reading what appears to be the foils for a conference talk by Barry Kelly, and found on p. 13 something that looked really interesting: TRTTIConstructor.Invoke. In an adjacent bullet point, one finds "Dynamically construct instances w...

Avoiding RTTI In Java

Hi, If I have a superclass, say Animal, and two subclasses: Zebra and Giraffe, If I decide to define a Vector of Animals: Vector <Animal> animals = new Vector(); and I want to say: You can add Giraffes, but you must own at least one Zebra first. What is the best way to do this without using RTTI? (instanceof) ...

Delphi: how to set the length of a RTTI-accessed dynamic array using DynArraySetLength?

I'd like to set the length of a dynamic array, as suggested in this post. I have two classes TMyClass and the related TChildClass defined as TChildClass = class private FField1: string; FField2: string; end; TMyClass = class private FField1: TChildClass; FField2: Array of TChildClass; end; The array augmentation is implem...

C++ DLL Injection get Struct values

I am trying inject into a dll that sends a void ** for one of the parameters. The void ** can contain structs that are created in the application. Is there any way of getting data out of the structs. ...

Delphi: RTTI and TObjectList<TObject>

Based on one answer to an earlier post, I'm investigating the possibility of the following design TChildClass = class(TObject) private FField1: string; FField2: string; end; TMyClass = class(TObject) private FField1: TChildClass; FField2: TObjectList<TChildClass>; end; Now, in the real world, TMyClass will have 10 differe...

Using Visual sudio .ncb file for reflection.

I am developing visual game level editor in c++. For this I want reflection(RTTI) mechanism to know class attributes at runtime. I am currently using PDB files for this.But using PDB I couldn't retrieve actual code line for extra information in commented format which is given for that attribute. Visual studio uses NCB files for intellige...

activate RTTI in c++

Hi, Can anybody tell me how to activate RTTI in c++ when working on unix. I heard that it can be disabled and enabled. on my unix environment,how could i check whether RTTI is enabled or disabled? I am using the aCC compiler on HPUX. ...

Practical usage for Delphi's new RTTI - Attributes,Values

I found great explanation about the new RTTI in Delphi,but I don't understand one important thing about all I have read - Where can I use that? What is it supposed to replace? ...

Delphi getting property value of a member from ClassType

I am implementing a Boilerplate feature - allow users to Change descriptions of some components - like Tlabels - at run time. e.g. TFooClass = Class ( TBaseClass) Label : Tlabel; ... End; Var FooClass : TFooClass; ... At Design time, the value Label's caption property is say - 'First Name', when the application is run, there ...

Passing Derived Class Instances as void* to Generic Callbacks in C++

This is a bit of an involved problem, so I'll do the best I can to explain what's going on. If I miss something, please tell me so I can clarify. We have a callback system where on one side a module or application provides a "Service" and clients can perform actions with this Service (A very rudimentary IPC, basically). For future refer...