rtti

Delphi RTTI: Get property's class

旧街凉风 提交于 2019-12-22 05:57:09
问题 Using Delphi 2010 and RTTI, I know how to get the class type of an object and how to get/set the value and type of an object's properties, but how do you determine which class in the inheritance chain a property came from? I want to use the properties of a base class differently than the main class. Consider this code: TClassBase = class(TObject) published property A: Integer; end; TClassDescendant = class(TClassBase) published property B: Integer; end; procedure CheckProperties(Obj: TObject)

Polymorphically catching an exception in a -fno-rtti shared library on Mac OS X

泄露秘密 提交于 2019-12-22 05:23:09
问题 I'm building a shared library with f-no-rtti . Internally, this library throws std:invalid_argument and catches std::exception , but the catch clause is never entered. The following code reproduces the problem (g++ 4.2, Mac OS X 10.6): // library.cpp: exports f(), compiled with -fno-rtti #include <stdexcept> #include <iostream> extern "C" { void f() { try { throw std::invalid_argument("std::exception handler"); } catch( std::exception& e) { std::cout << e.what() << "\n"; } catch(...) { std:

How to get the typeid of a void* pointer?

烂漫一生 提交于 2019-12-22 04:16:23
问题 I have a list of pointers to objects. These objects have nothing in common (i.e. no common base class); for better understanding: It is a list of objects that lie under the mouse cursor in a GUI. Now I would like to know what kind of object it is. A node, a node handle, a line segment, a tag, and so on. However I cannot use typeid(*ptr) since ptr is a const void* . Any solution for this? Can I force the usage of typeid since I know that the pointers always point to objects and not to mere

Is an object allowed to legally change its type during its lifetime in C++?

Deadly 提交于 2019-12-22 04:10:39
问题 I have this code: class Class { public: virtual void first() {}; virtual void second() {}; }; Class* object = new Class(); object->first(); object->second(); delete object; that I compile with Visual C++ 10 with /O2 and have this disassembly: 282: Class* object = new Class(); 00403953 push 4 00403955 call dword ptr [__imp_operator new (4050BCh)] 0040395B add esp,4 0040395E test eax,eax 00403960 je wmain+1Ch (40396Ch) 00403962 mov dword ptr [eax],offset Class::`vftable' (4056A4h) 00403968 mov

Enable Delphi XE RTTI only for some classes

老子叫甜甜 提交于 2019-12-22 03:58:19
问题 I'm trying to have RTTI enabled only for a subset of my classes. The reason is that for those classes for which I want RTTI, I want RTTI on public methods too, but if that is enabled project-wide, then all public methods from all classes get into the final executable. This basically turns off the smart-linking, as the compiler considers that every public method could be called at runtime, and thus ends up compiling pretty much everything and the kitchen sink into the executable... I've tried

How to get the property type name for custom properties?

与世无争的帅哥 提交于 2019-12-21 20:28:54
问题 In Delphi 2007, I added a new string type to my project: type String40 = string; This property is used in a class: type TPerson = class private FFirstName = String40; published FirstName: string40 read FFirstName write FFirstName; end; During runtime, I want to get the name of the property FirstName by using RTTI. I expect it to be String40: var MyPropInfo: TPropInfo; PropTypeName: string; MyPerson: TPerson; begin MyPerson := TPerson.Create; MyPropInfo := GetPropInfo(MyPerson, 'FirstName')^;

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

扶醉桌前 提交于 2019-12-21 12:20:13
问题 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 ClearMap; propCount := GetPropList(PTypeInfo(AClass.ClassInfo), propList); for ix := 0 to propCount - 1 do begin propInfo := propList^[ix]; propType := propInfo^.PropType; if

Is it possible to strip type names from executable while keeping RTTI enabled?

最后都变了- 提交于 2019-12-21 06:25:11
问题 I recently disabled RTTI on my compiler (MSVC10) and the executable size decreased significantly. By comparing the produced executables using a text editor, I found that the RTTI-less version contains much less symbol names, explaining the saved space. AFAIK, those symbol names are only used to fill the type_info structure associated with each the polymorphic type, and one can programmatically access them calling type_info::name() . According to the standard, the format of the string returned

Is it possible to strip type names from executable while keeping RTTI enabled?

独自空忆成欢 提交于 2019-12-21 06:24:12
问题 I recently disabled RTTI on my compiler (MSVC10) and the executable size decreased significantly. By comparing the produced executables using a text editor, I found that the RTTI-less version contains much less symbol names, explaining the saved space. AFAIK, those symbol names are only used to fill the type_info structure associated with each the polymorphic type, and one can programmatically access them calling type_info::name() . According to the standard, the format of the string returned

how i can set the value of a nested property using the RTTI

安稳与你 提交于 2019-12-21 05:28:30
问题 Check this simplified sample (the real scenario is different), I want to set tne value of a nested property of a object, in this case set the color of the Font for a TLabel component to clRed using RTTI. var p : TRttiProperty; p2: TRttiProperty; c : TRttiContext; begin c := TRttiContext.Create; try p := c.GetType(Label1.ClassInfo).GetProperty('Font'); p2 := c.GetType(p.PropertyType.Handle).GetProperty('Color'); p2.SetValue(p.PropertyType.AsInstance,clred); //this line is not working finally c