rtti

Practical usage for Delphi's new RTTI - Attributes,Values

戏子无情 提交于 2019-11-28 05:56:46
I found a great explanation about the new RTTI in Delphi ,but I don't understand one important thing about all I have read - Where can I use that? What is it supposed to replace? Runner The extended RTTI works like Reflection in .NET. It gives you access to your internal application structure information. You can access class properties, methods etc.. at runtime, at extent you could not do it before. Some ways of using it: Serialization / Deserialization of classes to XML or other media Mapping of objects to databases. ORM. Cloning of objects Dynamic invocation of methods "Scanning" of object

Getting type of record field with RTTI fails for static arrays

巧了我就是萌 提交于 2019-11-28 03:50:05
问题 I am trying to get types for record fields in order to create correct comparer (as general solution for any/almost any record type). I can't find type information for static arrays: TArrFieldTest = record a: string; b: array[0..3] of byte; end; procedure Test; var rttiContext: TRttiContext; rttiType: TRttiType; rttiFields: TArray<TRttiField>; begin rttiType := rttiContext.GetType(TypeInfo(TArrFieldTest)); rttiFields := rttiType.GetFields; Assert(rttiFields[0].FieldType<>nil); // it's ok

Why should I care about RTTI in Delphi?

烈酒焚心 提交于 2019-11-28 03:48:41
I've heard a lot about the new/improved RTTI capabilities of Delphi 2010 , but I must admit my ignorance...I don't understand it. I know every version of Delphi has supported RTTI...and I know that RTTI (Runtime Type Information) allows me to access type information while my application is running. But what exactly does that mean ? Is Delphi 2010's RTTI support the same thing as reflection in .NET ? Could someone please explain why RTTI is useful? Pretend I'm your pointy haired boss and help me understand why RTTI is cool. How might I use it in a real-world application? RTTI in Delphi is still

How can I get the sub-item type of a TObjectList<T> purely by RTTI information (i.e. without using any actual object instance) in Delphi?

淺唱寂寞╮ 提交于 2019-11-28 02:19:39
问题 I'm implementing generic code for streaming arbitrary Delphi objects using RTTI, and in order to get this to work (more specifically, in order to get the loading part to work), I need to somehow get the sub-item type of a TObjectList<T> field without making use of any actual object instance. The obvious reason for the requirement to not use any actual object instance is that in the case of loading an object from a stream (based solely on the knowledge of the class type of the object to be

Duplicating components at Run-Time

蓝咒 提交于 2019-11-28 00:51:02
Is there a simple way to duplicate all child components under parent component, including their published properties? For example: TPanel TLabel TEdit TListView TSpecialClassX Of course the most important factor, it should duplicate any new component which I drop on the TPanel without modifying the code under normal circumstances. I've heard of the RTTI, but never used it actually. Any ideas? have a read of this page Run-Time Type Information In Delphi - Can It Do Anything For You? Noting the section Copying Properties From A Component To Another which has a unit, RTTIUnit with a Procedure,

RTTI Overhead in C++

你离开我真会死。 提交于 2019-11-27 21:37:34
问题 What are the memory/performance overheads of enabling RTTI in a C++ program? Can anyone please throw some light between the internal implementation of RTTI mechanism and the relevant overheads? I do understand how to use RTTI through typeid and dynamic_cast , what I am trying to know is the internal implementation details of how the run time keeps track of this information and how it is an overhead? 回答1: Enabling RTTI typically brings only a small overhead. The usual implementation carries a

Java isInstance vs instanceOf operator

僤鯓⒐⒋嵵緔 提交于 2019-11-27 21:10:50
The whole generics thing is kinda throwing me for a loop, and more so the RTT. Specificis? Ah well here's the gist: enum QueryHelper { query1, query2; static <T> QueryHelper getQueryHelper (Class<T> expectedReturn) { if (expectedReturn.isInstance (SomeRelatedClass.class)) return query1; else return query2; } } and then I would call it like so: ... QueryHelper helper = QueryHelper.getQueryHelper(SomeRelatedClass.class); ... This is so that I can really flexibly assign the query return type in the actual helper. It does some casting and object creation. What I am seeing is that there is no match

Creating a new object from dynamic type info

こ雲淡風輕ζ 提交于 2019-11-27 19:25:39
In C++, is there any way to query the type of an object and then use that information to dynamically create a new object of the same type? For example, say I have a simple 3 class hierarchy: class Base class Foo : public Base class Bar : public Base Now suppose I give you an object cast as type Base -- which is in reality of type Foo. Is there a way to query the type and use that info to later create new objects of type Foo? Clone method There is nothing provided by the language that queries type and lets you construct from that information, but you can provide the capability for your class

How can I make sure RTTI is available for a class without instantiating it?

烈酒焚心 提交于 2019-11-27 18:21:13
问题 I've recently posted a question in this forum asking for any advice regarding missing RTTI information in a DXE2 executable. That post was a stripped down version of my actual case. RRUZ came to the rescue, and so the stripped down version was quickly resolved. The original problem, though, is still standing, and so I'm posting it in full now. "Main": program MissingRTTI; {$APPTYPE CONSOLE} uses System.SysUtils, RTTI, MyUnit in 'MyUnit.pas', RTTIUtil in 'RTTIUtil.pas'; var RHelp: TRttiHelper;

How to use SuperObject to invoke methods that uses an Object as parameter in Delphi?

北慕城南 提交于 2019-11-27 18:11:34
问题 We can use the SuperObject library to invoke methods of a certain object by its name and giving its parameters as a json string using the SOInvoker method like in this answer I'd like to know how do I send a created object as a parameter. I tried to send it like LObjectList := TObjectList.Create; LSuperRttiCtx := TSuperRttiContext.Create; LSuperObjectParameter := LObjectList.ToJson(LSuperRttiCtx); SOInvoke(MyInstantiatedObject, 'MyMethod', LSuperObjectParameter); but inside MyMethod the