rtti

How can I make sure RTTI is available for a class without instantiating it?

半腔热情 提交于 2019-11-29 04:30:01
I've recently posted a question in this forum asking for any advice regarding missing RTTI information in a DXE2 executable. That post was a stripped down version of my actual case. RRUZ came to the rescue, and so the stripped down version was quickly resolved. The original problem, though, is still standing, and so I'm posting it in full now. "Main": program MissingRTTI; {$APPTYPE CONSOLE} uses System.SysUtils, RTTI, MyUnit in 'MyUnit.pas', RTTIUtil in 'RTTIUtil.pas'; var RHelp: TRttiHelper; begin RHelp := TRttiHelper.Create(); if (RHelp.IsTypeFound('MyUnit.TMyClass')) then WriteLn('TMyClass

How to use SuperObject to invoke methods that uses an Object as parameter in Delphi?

江枫思渺然 提交于 2019-11-29 04:06:14
We can use the SuperObject library to invoke methods of a certain object by its name and giving its parameters as a json string using the SOInvoker method like in this answer I'd like to know how do I send a created object as a parameter. I tried to send it like LObjectList := TObjectList.Create; LSuperRttiCtx := TSuperRttiContext.Create; LSuperObjectParameter := LObjectList.ToJson(LSuperRttiCtx); SOInvoke(MyInstantiatedObject, 'MyMethod', LSuperObjectParameter); but inside MyMethod the LObjectList reference is lost. What am I doing wrong? The superobject library can be downloaded here It will

RTTI Overhead in C++

我们两清 提交于 2019-11-29 01:23:42
What are the memory/performance overheads of enabling RTTI in a C++ program? Can anyone please throw some light between the internal implementation of RTTI mechanism and the relevant overheads? I do understand how to use RTTI through typeid and dynamic_cast , what I am trying to know is the internal implementation details of how the run time keeps track of this information and how it is an overhead? Enabling RTTI typically brings only a small overhead. The usual implementation carries a pointer to the type information structure in the vtable of an object. Since the vtable must be constructed

How to typeof in C++

蓝咒 提交于 2019-11-28 11:31:33
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 it loads those kinds of objects from a file (.so or .dll)? You could use a dynamic_cast to test types as shown below: IPlugin* iPluginPtr = NULL; iPluginPtr = dynamic_cast<IPlugin*>(somePluginPtr); if (iPluginPtr) { // Cast succeeded } else { // Cast failed } This

Delphi How to get default value for property using RTTI

五迷三道 提交于 2019-11-28 10:35:25
问题 If I have a class like this: TServerSettings = class(TSettings) strict private FHTTPPort : Integer; published property HTTPPort : Integer read FHTTPPort write FHTTPPort default 80; end; How can I get the default attribute of the HTTPPort property using RTTI? 回答1: Like this: {$APPTYPE CONSOLE} uses System.TypInfo; type TMyClass = class strict private FMyValue: Integer; published property MyValue: Integer read FMyValue default 42; end; var obj: TMyClass; PropInfo: PPropInfo; begin obj :=

activate RTTI in c++

半腔热情 提交于 2019-11-28 09:36:51
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. Are you using g++ or some other compiler? In g++ RTTI is enabled by default IIRC, and you can disable it with -fno-rtti . To test whether it is active or not use dynamic_cast or typeid UPDATE I believe that HPUX's aCC / aC++ also has RTTI on by default, and I am unaware of a way to disable it. Check your man pages . gcc has it on by default. Check if typeid(foo).name(

Delphi 2010 RTTI - RttiContext.FindType

荒凉一梦 提交于 2019-11-28 09:29:08
问题 With RttiContext.FindType('Classes.TStringList') I get RttiType of TStringList with no problem. But with RttiContext.FindType('MyUnit.TMyClass') I always get nil (of course MyUnit is in uses clause). Why, what is wrong? Example: unit MyUnit; interface uses Classes; type TMyClass = class(TStringList) end; implementation end. Main unit: ... uses MyUnit, ... var oCont: TRttiContext; oType: TRttiType; begin oCont := TRttiContext.Create; try oType := oCont.FindType('MyUnit.TMyClass'); <== oType =

access all elements of a record using RTTI

别等时光非礼了梦想. 提交于 2019-11-28 08:58:39
问题 I want to dump a complex / long record into a memo for debugging purpose TmyRecord = aValue : String aNumber : Real; Morenumbers : Integer ; .... .... end; I think Delphi XE 2 RTTI should give me the chance to get the Fieldname , Fieldtype and value within a loop, to write this record to a memo or ..... 回答1: As starting point - record with simple types. For complex fields (array, class etc) explore RTTI unit type TmyRecord = record aValue: String; aNumber: Real; Morenumbers: Integer; end; var

What are some 'good use' examples of dynamic casting?

痴心易碎 提交于 2019-11-28 08:10:34
We often hear/read that one should avoid dynamic casting. I was wondering what would be 'good use' examples of it, according to you? Edit: Yes, I'm aware of that other thread : it is indeed when reading one of the first answers there that I asked my question! Mark Ransom This recent thread gives an example of where it comes in handy. There is a base Shape class and classes Circle and Rectangle derived from it. In testing for equality, it is obvious that a Circle cannot be equal to a Rectangle and it would be a disaster to try to compare them. While iterating through a collection of pointers to

Extract C++ template parameters

霸气de小男生 提交于 2019-11-28 08:07:04
Although I'm doubtful, I'm curious as to whether it's possible to extract primitive-type template parameters from an existing type, perhaps using RTTI. For example: typedef std::bitset<16> WordSet; Would it be possible to extract the number 16 in the above code without hard-coding it elsewhere? Compiler specific implementations are welcome, though I'm particularly interested in g++ . It's not possible. The usual way you do it is this: template<int N> struct foo { static const int value = N; }; and for types template<typename T> struct foo { typedef T type; }; You can access it then as foo<39>: