rtti

Why does FindType fail to get RTTI when GetType succeeds?

被刻印的时光 ゝ 提交于 2019-12-23 19:36:58
问题 I'm trying to get hold of an object using TRttiContext.FindType(QualifiedTypeName) . Here's what I've got: program MissingRTTI; {$APPTYPE CONSOLE} uses System.SysUtils, RTTI, Classes; type TMyClass = class(TObject) end; var rCtx: TRttiContext; rType: TRttiInstanceType; begin rCtx := TRttiContext.Create(); rType := rCtx.GetType(TypeInfo(TMyClass)) as TRttiInstanceType; if (rType <> nil) then begin WriteLn('Type found using TypeInfo'); end; rType := rCtx.FindType(TMyClass.QualifiedClassName) as

What's the advantages of turning off RTTI from compiler setting?

有些话、适合烂在心里 提交于 2019-12-23 19:15:32
问题 By this(How expensive is RTTI?), it seems clear that dynamic casting is much expensive than static type comparison, but I wonder if it would be worth to turn off RTTI option in compiler option(VS2010, /GR-) I have no dynamic cast in my code(I replaced them with static cast). But does (/GR-) option do any other than emitting errors when using dynamic cast? Is there any memory or code optimization in there? Thanks in advance. 回答1: Straight from MSDN (emphasis mine): When /GR is on, the compiler

RTTI access to private methods of VCL, e.g. TCustomForm.SetWindowState

女生的网名这么多〃 提交于 2019-12-23 17:04:09
问题 In the debate about the closing of the class helper loophole that allowed easy access to private members (fields and methods) of a class in Delphi 10.1 Berlin, it is often claimed that extended RTTI allows access to the private members of a class that was compiled with (extended) RTTI enabled, and all VCL/RTL/FMX classes have this enabled. However, if I run this simple unit (a simple form with one TListBox, nothing else): unit RttiAccessTest; interface uses Winapi.Windows, Winapi.Messages,

Observer pattern with type information (C++)

社会主义新天地 提交于 2019-12-23 04:34:38
问题 i'm trying to implement a custom version of an Observer pattern in c++. These are my classes (just interface): class Observer{ public: void observe(std::string behaviour, Observable * observable); void stopObserving(std::string behaviour, Observable * observable); virtual void notified(std::string behaviour, Observable * observed); // ... }; class Observable{ public: void notifyBehaviour(std::string behaviour); // ... }; And can be used like this: class A : public Observer{ public: void

Using typeid for simple decisions

馋奶兔 提交于 2019-12-23 03:47:11
问题 My question concerns simple catching of casting problems at runtime in C++. I understand that C++ provides no 'RTTI' under most circumstances (let's just say I can't change my compiler settings and turn it on, for argument's sake.). In my project, I have a container provided to me by an ancient library. Let's call that Frodo and the container Bane. Frodo's Bane is a container I must interact with directly. It has been poorly implemented and contains several maps of the same information which

Pointer to the start of an object (C++)

三世轮回 提交于 2019-12-22 11:06:07
问题 I need a way to get a pointer to the start of an object in C++. This object is used inside a template so it can be any type (polymorphic or not) and could potentially be an object that uses multiple inheritance. I found this article which describes a way to do it (see the section called "Dynamic Casts") using typeid and a dynamic_cast to void* in the case that T is a polymorphic type. This works perfectly well on MSVC, however on GCC (4.x) it seems to fall on its arse and spits out a compiler

Rtti data manipulation and consistency in Delphi 2010

两盒软妹~` 提交于 2019-12-22 10:55:16
问题 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 and manipulate the data. My idea was to define a property for the Data: TDataModel <T> = class {...} private FData : TValue; function GetData : T; procedure

How to Set a Value to a Sub-Property Item using TypInfo RTTI Methods?

纵饮孤独 提交于 2019-12-22 09:38:47
问题 In my Question: How to use “Sender” parameter with “As” operator for more then one class at a time I choose the Remy Lebeau's Answer because it was the most dynamic tech for most situations like that. It uses the RTTI TypInfo Class. But as I was using this class, another problem came: How do we Set a sub-property value? function TRemote.UpdateQuery(DataSet: TDataSet; SQL: String): Boolean; var PropInfo: PPropInfo; begin { atualiza o código SQL padrão de um dataSet de consulta tipo View }

How to turn off RTTI in Visual Studio 2008

房东的猫 提交于 2019-12-22 08:42:45
问题 I am not sure about other versions, but, in VS 2008 even with RTTI disabled I can query the information by calling typeid(T).name() on the type. It works with all types, internal and user created. Our project has RTTI disabled but I was surprised to find that this still worked. Is this a Visual Studio bug or is the /GR- flag not enough to disable it? Does this fall into the realm of undefined behavior ? If it is not a bug, how do I really turn it off? 回答1: Is it possible that you used typeid

How to turn off RTTI in Visual Studio 2008

流过昼夜 提交于 2019-12-22 08:40:18
问题 I am not sure about other versions, but, in VS 2008 even with RTTI disabled I can query the information by calling typeid(T).name() on the type. It works with all types, internal and user created. Our project has RTTI disabled but I was surprised to find that this still worked. Is this a Visual Studio bug or is the /GR- flag not enough to disable it? Does this fall into the realm of undefined behavior ? If it is not a bug, how do I really turn it off? 回答1: Is it possible that you used typeid