rtti

std::type_info::hash_code() uniqueness and the meaning of “should”

余生长醉 提交于 2020-01-02 01:18:27
问题 Is it meant to be guaranteed that same std::type_info::hash_code() values imply same types? Cplusplus.com seems to claim so: This function returns the same value for any two type_info objects that compare equal, and different values for distinct types that do not. [Emphasis mine] Cppreference seems to claim otherwise: Returns an unspecified value, which is identical for objects, referring to the same type. No other guarantees are given , in particular, the value can change between invocations

How can I get a dataset of in-memory objects?

柔情痞子 提交于 2020-01-01 04:58:12
问题 Does anyone know of a TDataset descendant that works with Generics and RTTI, so that I can write code like this, and make use of data-aware components in the GUI? : ... ds:TDataset<TPerson>; ... procedure DoStuff; begin ds:=TDataset<TPerson>.create; ds.add(TPerson.Create('A.','Hitler',77)); ds.add(TPerson.Create('O.','Bin Laden',88)); end; This should be possible. The fielddefs can be created via RTTI because the exact type of the data is known. Values can also be automatically marshalled

How to copy the properties of one class instance to another instance of the same class?

こ雲淡風輕ζ 提交于 2019-12-30 11:39:17
问题 I want to duplicate a class. It is sufficient that I copy all properties of that class. Is it possible to: loop thru all properties of a class? assign each property to the other property, like a.prop := b.prop ? The getters and setters should take care of the underlying implementation details. EDIT: As Francois pointed out I did not word my question carefully enough. I hope the new wording of the question is better SOLUTION: Linas got the right solution. Find a small demo program below.

Checking the object type in C++11

廉价感情. 提交于 2019-12-30 06:53:12
问题 I have class B that inherits from A. class A { }; class B : public A { }; And I have three objects. A* a = new A(); A* a2 = new B(); B* b = new B(); I'd like to if check a is object of type A, a2 is object of type B (not A), and b is object of type B. I tried typed comparison, but it doesn't give me correct answer. cout << (typeid(*a) == typeid(A)) << endl; // -> 1 cout << (typeid(*a2) == typeid(A)) << endl; // -> 1 cout << (typeid(*b) == typeid(A)) << endl; // -> 0 cout << (typeid(*a) ==

Delphi: At runtime find classes that descend from a given base class?

痴心易碎 提交于 2019-12-29 05:26:12
问题 Is there at way, at runtime, to find all classes that descend from a particular base class? For example, pretend there is a class: TLocalization = class(TObject) ... public function GetLanguageName: string; end; or pretend there is a class: TTestCase = class(TObject) ... public procedure Run; virtual; end; or pretend there is a class: TPlugIn = class(TObject) ... public procedure Execute; virtual; end; or pretend there is a class: TTheClassImInterestedIn = class(TObject) ... public procedure

Safe Dynamic JSON Casts In Swift

独自空忆成欢 提交于 2019-12-24 13:12:17
问题 I suspect that I am not quite grokking Swift 1.2, and I need to RTFM a bit more. I'm working on a Swift app that reads JSON data from a URI. If the JSON data is bad, or nonexistent, no issue. The JSON object never instantiates. However, if the JSON data is good JSON, but not what I want, the object instantiates, but contains a structure that is not what I'm looking for, I get a runtime error. I looked at using Swift's "RTTI" (dynamicType), but that always returns "<Swift.AnyObject>", no

Can one get/set class-level members using Enhanced RTTI in Delphi?

ぐ巨炮叔叔 提交于 2019-12-24 13:10:59
问题 Preface, it seems i failed to say it clear. I want to enumerate, read and set, all the class var or class properties of a given TClass variable. There is no problem in finding TClass - it is passed. There is no problem in filtering by presence of given attribute. There problem is that RTTI just misses the way to enumerate class fields rather than instance fields. I wanted to make a declarative DLL Loader. Since the DLLs are process-global in windows (you cannot load the same DLL twice) it

delphi Creating Component template

跟風遠走 提交于 2019-12-24 07:31:14
问题 I am working with Delphi application.I created one form shown as below: I wanted to make component out of this controls through code . But not through component-->create component Template -->so on. How do i make component template out of form contols through delphi code .?? Thanx in advance. 回答1: Or if you want to have that group of controls as one single component you can install unit like this into some package: unit EditGroup; interface uses SysUtils, Classes, Graphics, Controls, StdCtrls

Why does dynamic cast from class to subclass requires the class to be polymorphic?

孤人 提交于 2019-12-24 02:59:12
问题 As I understand it, what makes dynamic cast different from a static cast is its use of RTTI, and the fact that it fails if the dynamic type of a variable- when casting from base to derived- does not fit. But why does the class have to be polymorphic for that to be done if we have the RTTI anyway? EDIT: Since there was some confusion about the use of the word "polymorphic", here's the entry in cplusplus.com that prompted me to ask this: dynamic_cast can be used only with pointers and