rtti

Subclassing class from shared library compiled with -fno-rtti

大兔子大兔子 提交于 2019-12-05 20:40:40
问题 I am trying to subclass from a shared library which was compiled with -fno-rtti. Unfortunately other libraries in my code base require -frtti. As a result I am getting link errors because the superclass does not have a typeinfo struct. Error received in a normal compilation: out.o: in function typeinfo for MyClass:myclass.cpp(.data.rel.ro.<cpp magic>): error: undefined reference to 'typeinfo for NetlinkListener' The class I want to subclass is an android class in libsysutils (snipped a little

Delphi: RTTI and TObjectList<TObject>

≡放荡痞女 提交于 2019-12-05 16:36:49
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 different lists like this, so I would like to be able to address these lists using RTTI. However, I'm not interested in the other fields of this class, so I need to check if a certain field is some sort of TObjectList. This is what I've got so far: procedure InitializeClass(RContext

Delphi Superobject, generic list to json

£可爱£侵袭症+ 提交于 2019-12-05 15:27:18
I have a object with some TObjectList<>-fields that I try to encode as JSON with help form SuperObject . TLogs = TObjectList<TLog>; TMyObject = class(TObject) private FLogs: TLogs; end; Deep inside SuperObjects code, there is a ToClass procedure, iterating the fields and add them to the json result. In this loop, there is a check on the TRttiFields FieldType. If it's nil, it skips the object. for f in Context.GetType(Value.AsObject.ClassType).GetFields do if f.FieldType <> nil then begin v := f.GetValue(value.AsObject); result.AsObject[GetFieldName(f)] := ToJson(v, index); end My generic list

How can I distinguish TDateTime properties from Double properties with RTTI?

感情迁移 提交于 2019-12-05 13:21:50
问题 Using the RTTI system in Delphi 2010, is there any way to find out if a property is a TDateTime? It's currently treating it as a double whenever I call back asVariant and also if I check the property type. Is this due to the fact it can only see the base type? (TDateTime = double) 回答1: Try checking the Name property of the TRttiProperty.PropertyType I don't have Delphi 2010, but this works in XE. {$APPTYPE CONSOLE} uses SysUtils, Classes, Rtti; type TMyClass =class private FDate: TDateTime;

Delphi RTTI: Get property's class

和自甴很熟 提交于 2019-12-05 10:22:50
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); var ctx: TRttiContext; objType: TRttiType; Prop: TRttiProperty; begin ctx := TRttiContext.Create;

Find all Class Helpers in Delphi at runtime using RTTI?

↘锁芯ラ 提交于 2019-12-05 09:56:11
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 third party components or libraries without source code, which would make it easy to grep class helpers. Since class helpers only apply to a class based on what helper is "closest" in scope, a class simply cannot know that a helper exists. For example, you can

What's the difference between public and published class members in Delphi?

浪子不回头ぞ 提交于 2019-12-05 08:40:28
问题 Please could someone explain me what's the difference between public and published class members in Delphi? I tried to look at Delphi help and I understand that these members have the same visibility, but I don't understand very well how they differ and when should I use published members instead of public ones. Thanks a lot. 回答1: Public properties and published properties have the same visibility, as you already stated. Published properties are included in RTTI, public properties aren't. 回答2

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

扶醉桌前 提交于 2019-12-05 07:49:24
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::cout << "... handler\n"; } } } // main.cpp: the main executable, dynamically loads the library #include

C++: is a class with virtual base but without virtual functions polymorphic and has VTable?

两盒软妹~` 提交于 2019-12-05 05:55:47
Consider the following code: #include <iostream> #include <typeinfo> #include <type_traits> using namespace std; struct A { int data; }; struct B1 : A {}; struct B2 : virtual A {}; struct Base1 : virtual A {}; struct Base2 : virtual A {}; struct Derived : Base1, Base2 {}; int main() { cout << sizeof(B1) << endl; cout << sizeof(B2) << endl; cout << sizeof(Derived) << endl; cout << std::is_polymorphic<B1>::value << endl; cout << std::is_polymorphic<B2>::value << endl; cout << std::is_polymorphic<Derived>::value << endl; return 0; } On my system it prints 4 8 12 0 0 0 Which means that none of