rtti

How to get the name of an interface at runtime?

If I have an object that implements an interface, it's not too difficult to use RTTI to look up the interface and obtain its GUID. But if I want its name, is there any way to get that? It's simple enough to get a class's name, but for interfaces it seems a bit trickier... ...

Is it allowed to link rtti enabled DLL within rtti disabled application?

I have a solution to build a DLL with run-time type information enabled in its project properties. This is the default (/GR) in Visual studio 2005. In our library we have a good few dynamic_casts, so I'm not able currently to build the DLL without run-time type information. Now my customer is using development tools from Dassault Systèm...

What is the best way to serialize Delphi application configuration?

I will answer this question myself, but feel free to provide your answers if you are faster than me or if you don't like my solution. I just came up with this idea and would like to have some opinions on that. Goal: a configuration class that is readable (like an INI-file) but without having to write (and adapt after a new configuration...

How to call GetEnumerator on arbitrary type?

I'm writing a control that should be able to display any list of data. What I wanted to do, was to mimic the for-in construct in that I check for a public GetEnumerator function that contain a Current property and a MoveNext method. I've determined the following: I can check the existance of a method by simply calling MethodAddress on...

There a way to determine at runtime if an object can do a method in C++

In Perl, there is a UNIVERSAL::can method you can call on any class or object to determine if its able to do something: sub FooBar::foo {} print "Yup!\n" if FooBar->can('foo'); #prints "Yup!" Say I have a base class pointer in C++ that can be any of a number of different derived classes, is there an easy way to accomplish something si...

Static cast vs. dymamic cast for traversing inheritance hierarchies

I saw one book on C++ mentioning that navigating inheritance hierarchies using static cast is more efficient than using dynamic cast. Example: #include <iostream> #include <typeinfo> using namespace std; class Shape { public: virtual ~Shape() {}; }; class Circle : public Shape {}; class Square : public Shape {}; class Other {}; int ...

How can I assign an interface variable to a variable of type Rtti.TValue

At the moment I give delphi2010 a trial and found the TValue type of the Rtti Unit. TValue have very interessting features, but I can't find a way to assign an interface. I try the following program Project1; uses Classes, SysUtils, Rtti; var list : IInterfaceList; value : TValue; begin // all these assignments works value...

Delphi call method based on RTTI information

Hey all, first sorry for my bad english. Consider the following (not actual code): IMyInterface = Interface(IInterfce) procedure Go(); end; MyClass = class(IMyInterface) procedure Go(); end; MyOtherClass = class published property name: string; property data: MyClass; end; I'm setting "MyOtherClass" properties using RTTI. Fo...

Convert a DevExpress TcxFilterOperatorKind to and from a string ?

Hi! Here is a codesnippet I use to get filtertype operator from a filter in a DevExpress grid: OperatorKindToStr is used to extract operatorkind from a filter as string and store it in a xml-file. StrToOperatorKind is used to convert back a string from xml to set an operatorkind in a filter. const CUSTFILTER_FILTERITEM = 'FilterI...

Qt RTTI trouble

In a quest for handling events (like mouse moves and clicks) not by subclassing, one has to use installEventFilter and provide an event handler. While doing so, I've encountered a problem with RTTI support, meaning that typeid().name() gives QObject * all the time, no matter on which object event was triggered. There is, of course, anoth...

Run-time type information in C++

Hi, What is runtime type control in C++? P.Gopalakrishnan. ...

Why do I get "type has no typeinfo" error with an enum type

I have declared the following enum type in which I want the first member to have the ordinal value of 1 (one) rather than the usual 0 (zero): type TMyEnum = ( meFirstValue = 1, meSecondValue, meThirdValue ); If I call TypeInfo(), e.g. as part of a call to GetEnumName(), ...

TPersistent + interface, Delphi

Hi, I need a class that is based on TPersistent (so it stores the RTTI) and includes default Interfaces handling (QueryInterface, _AddRef, _Release) ... what is the class name I'm looking for? ...

How to set event handlers via new RTTI? [D2010]

Hi all, Playing with new RTTI module, I couldn't find a way to set an event handler with the new utilities. Trying something like this: LProp := TRttiContext.Create.GetType(Form1.ClassInfo).AsInstance.GetProperty('OnClick'); LProp.SetValue(Form1, {a TValue!}); SetValue needs a TValue passed but I've yet to find a way to represent a T...

Mixing RTTI flags in C++

If I have multiple linked C++ statically linked libraries in C++, is it possible for them to share (pass to and from functions) class objects if they have been compiled with differing values of enabled/disabled run time type information (RTTI)? --edit: Thanks for the responses, the specific things I was worried about was 1. Does enablin...

How to typeof in C++

How to simulate C# typeof-command behavior in C++? C# example: public static PluginNodeList GetPlugins (Type type) { ... } Call: PluginManager.GetPlugins (typeof(IPlugin)) How to implement this using C++? Maybe QT or Boost libraries provide a solution? What about the case if you want to implement .GetPlugins(...) in a way that i...

How to get access field in Delphi using RTTI?

Hi all, and sorry for my English. Consider the following: TFieldType = class fValue: string; end; TMainClass = class private Ffield: TFieldType; public function GetValue: string; end; In TMainClass.GetValue I'm tryin get values of TMainClass fields: function TMainClass.GetValue; begin vCtx := TRTTIContext.Create; vType := ...

Discovering the class where a property is first published with multiple levels of inheritence.

Using the Typinfo unit, it is easy to enumerate properties as seen in the following snippet: procedure TYRPropertiesMap.InitFrom(AClass: TClass; InheritLevel: Integer = 0); var propInfo: PPropInfo; propCount: Integer; propList: PPropList; propType: PPTypeInfo; pm: TYRPropertyMap; classInfo: TClassInfo; ix: Integer; begin ...

Delphi 2010: New RTTI, setting propertyvalue to arbitary value

TRTTIProperty.SetValue( ) takes an TValue instance, but if the provided TValue instance is based on a different type then the property, things blow up. E.g. TMyObject = class published property StringValue: string read FStringValue write FStringValue; end; procedure SetProperty(obj: TMyObject); var context: TRTTIContext; rtti: T...

Trouble playing with indexed propertes via new RTTI [D2010]

ShowMessage(TRttiContext.Create.GetType(TStringList) .GetProperty('Strings').ToString); Above code fails as .GetProperty returns nil on properties like "Strings", "Objects", "Values" (ones with indexers). I assume this is a known limitation and the question is if there's any way to access those indexed properties (preferably with...