rtti

Why does creating a TRttiContext in advance make my RTTI tests run faster?

こ雲淡風輕ζ 提交于 2019-12-12 09:54:14
问题 Linked to the original question Is it possible to get the index of class property? and answered by Remy Lebeau and RRUZ program Demo; {$APPTYPE CONSOLE} uses System.SysUtils, Winapi.Windows, System.Rtti, System.TypInfo; type TMyClass = class private function GetInteger(const Index: Integer): Integer; procedure SetInteger(const Index, Value: Integer); public property P1: Integer Index 1 read GetInteger write SetInteger; property P2: Integer Index 2 read GetInteger write SetInteger; property P3

Delphi Superobject, generic list to json

廉价感情. 提交于 2019-12-12 09:40:55
问题 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 :=

How to get the class type reference by its name in Delphi XE?

徘徊边缘 提交于 2019-12-12 08:53:50
问题 I'm actually trying to use Rtti to implent a generic method invoker. It should work like this: I'll provide the class name, method name, and arguments the invoker will do its work by invoking the specified method of this class So I need the class reference in order to get its Rtti information and seek for the method I want to invoke. Is there any way to do that without implementing a class reference list of the classes I want to be working with? 回答1: To get the class reference using his name

Delphi TRttiType.GetMethods return zero TRttiMethod instances

折月煮酒 提交于 2019-12-11 07:34:25
问题 I've recently been able to fetch a TRttiType for an interface using TRttiContext.FindType using Robert Loves "GetType"-workaround ("registering" the interface by an explicit call to ctx.GetType, e.g. RType := ctx.GetType(TypeInfo(IMyPrettyLittleInterface));). One logical next step would be to iterate the methods of said interface. Consider program rtti_sb_1; {$APPTYPE CONSOLE} uses SysUtils, Rtti, mynamespace in 'mynamespace.pas'; var ctx: TRttiContext; RType: TRttiType; Method: TRttiMethod;

Does boost::any need RTTI?

狂风中的少年 提交于 2019-12-11 05:53:22
问题 On the Boost web site I found no information regarding the use or RTTI by boost::any. I read in a few places that this is a requirement, but then I built a simple test project, and it builds both with and without RTTI. So, is RTTI, with its performance and memory issues, needed by boost::any and similar classes? 回答1: Since boost 1.57 RTTI is not needed for boost::any . Rememeber that all objects used as boost::any must by copyable. https://svn.boost.org/trac/boost/ticket/10346 来源: https:/

cast base class pointer to one of several possible derived type pointer based on condition

半世苍凉 提交于 2019-12-11 05:27:48
问题 I have a base class B and several derived template classes D<int> , D<float> , D<double> , etc. (so more than ten) In my program, I find a situation where I have a B pointer that I KNOW points to an instance one of the D specializations. I also have a unique key that identifies the derived type. So, I want to call the correct derived class method using my base class pointer and the unique type key. I actually want to do this in several places, so the one solution I have come up with is not

Circumventing RTTI on legacy code

好久不见. 提交于 2019-12-11 04:48:03
问题 I have been looking for a way to get around the slowness of the dynamic cast type checking. Before you start saying I should redesign everything, let me inform you that the design was decided on 5 years ago. I can't fix all 400,000 lines of code that came after (I wish I could), but I can make some changes. I have run this little test on type identification: #include <iostream> #include <typeinfo> #include <stdint.h> #include <ctime> using namespace std; #define ADD_TYPE_ID \ static intptr_t

How to determine using Rtti, if a field from a class is a Record

旧街凉风 提交于 2019-12-11 04:03:22
问题 I coded a RttiHelper class, that among other things, can retrieve all field's names of a class. The procedure succesfully determines if a field is an object or an array, but it cannot determine if a field is a Record. Follows code: unit Form1 interface uses RttiHelper; type tMyRec = Record ... end; ... implementation var MyRec : tMyRec; procedure FormCreate (Sender: tObject); begin SetRec (@MyRec); end; unit RttiHelper interface type tObjRec = class Rec : Pointer; end; ... tRttiHelperClass =

RTTI properties not returned for fixed enumerations: is it a bug?

Deadly 提交于 2019-12-11 02:54:27
问题 I need to browse all published properties of some classes. Properties where the type is an enumeration with fixed values are not listed. See example below: TMyEnum = (meBlue, meRed, meGreen); TMyEnumWithVals = (mevBlue=1, mevRed=2, mevGreen=3); TMyClass = ... published property Color: TMyEnum read FColor write SetColor; // This one is found property ColorVal: TMyEnumWithVals read FColorVal write SetColorVal; // This one is never found end; I need fixed values because these properties are

type_info doesn't account for cv qualifiers: is this right?

梦想的初衷 提交于 2019-12-10 16:20:14
问题 Is it the correct behaviour or is it a quirk of g++4.5 that this code prints 1? #include <iostream> #include <typeinfo> using namespace std; int main(){ struct A{}; cout<<(typeid(A)==typeid(const A)&&typeid(A)==typeid(const volatile A)&&typeid(A)==typeid(volatile A)); } I thought that types differing for cv-qualifiers were threated as very distinct types, even though less cv-qualified types could be implicitly cast to more cv-qualified types. 回答1: typeid ignores cv qualifiers, as per the C++