Questions tagged [rtti]

RTTI stands for Run-Time Type Information, it is also known as reflection; it allows access to compile-time data at run-time.

RTTI refers to the ability of the system to report on the dynamic type of an object and to provide information about that type at runtime (as opposed to at compile time). When utilized consistently, it can be a powerful tool to ease the work of the programmer in managing resources, or as the basis for writing reflective code. Further explanation can be found on Wikipedia

824 questions
7
votes
1 answer

Rtti does not work with generics types used as class fields

I had problems using rtti to get information about class fields of a generic type. After quite some googleing I found an entry in QC describing the issue. My question is, if anybody knows a workaround, or if this got fixed Delphi XE2. Below is the…
iamjoosy
  • 3,299
  • 20
  • 30
7
votes
1 answer

Get an attribute value of specific property

I have a class with published props which I serialize into XML. MyAttr = class(TCustomAttribute) private FName: string; public constructor Create(const Name: string); property Name: string read FName write FName; end; MyClass =…
Yuriy
  • 257
  • 5
  • 12
7
votes
3 answers

How to access a variable by its name(string)?

I have some global string variables. I have to create the function that I could pass & store them in some structure. Later I need to enumerate them and check their values. how can this be easily achieved? (I think I would need some kind of…
John
  • 1,834
  • 5
  • 32
  • 60
7
votes
2 answers

Why are some properties repeated when TRttiContext.GetType is called on a VCL Control?

Why are some properties repeated (such as Action and Align) where others are not (AlignWithMargins) when TRttiContext.GetType is called on a VCL Control? uses System.RTTI, System.Generics.Collections, …
Alister
  • 6,527
  • 4
  • 46
  • 70
7
votes
2 answers

RTTI: Get length of a character column

My function module receives a table name and a column name at runtime. I would like to get the length of the column: How many characters are allowed in the transparent table? I used my favorite search engine and found RTTS. But the examples in the…
guettli
  • 25,042
  • 81
  • 346
  • 663
7
votes
3 answers

What is the "correct OOP" way to deal with a storage pool of items of mixed types?

This was inspired by a comment to my other question here: How do you "not repeat yourself" when giving a class an accessible "name" in C++? nvoight: "RTTI is bad because it's a hint you are not doing good OOP. Doing your own homebrew RTTI does not…
The_Sympathizer
  • 1,191
  • 9
  • 17
7
votes
2 answers

Getting the Unit Name which belongs to any type (TRttiType)

I need to get the name of the unit (namespace) of any TRttiType. so far, I have tried the following. 1) using the PTypeData.UnitName, this solution works, but only when the TTypeKind is tkClass. procedure ListAllUnits; var ctx : TRttiContext; …
RRUZ
  • 134,889
  • 20
  • 356
  • 483
7
votes
2 answers

Is type_info not a part of RTTI?

I had asked a question Do C++ POD types have RTTI? and someone told me in the comments: POD types do have type_info, but don't have RTTI, and that's possible because type_info isn't always RTTI. and it seems right as i could get the type_info of…
Sadeq
  • 7,795
  • 4
  • 34
  • 45
7
votes
4 answers

Get the offset of a field in a delphi record at runtime

Given a record type: TItem = record UPC : string[20]; Price : Currency; Cost : Currency; ... end; And the name of a field as a string, how can I get the offset of that field within the record? I need to do this at runtime - the name of…
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
7
votes
1 answer

When using RTTI how can we get and set deeper level sub-properties?

Overview I appreciate a couple of similar questions have already been asked before: Get/Set sub properties ussing RTTI Get a sub property of a component in Delphi using RTTI how i can set the value of a nested property using the RTTI How can I…
Craig
  • 1,874
  • 13
  • 41
7
votes
1 answer

How can I store the type parameter(s) of a parameterized method and later use them to convert a JSON object to a plain object of the generic type?

I am attempting to write a generic messaging passing system for Delphi and .NET. The system allows messages to be defined as plain objects and message handlers are defined as anonymous methods that act on those objects. The objects are converted to…
Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117
7
votes
3 answers

Rtti accessing fields and properties in complex data structures

As already discussed in Rtti data manipulation and consistency in Delphi 2010 a consistency between the original data and rtti values can be reached by accessing members by using a pair of TRttiField and an instance pointer. This would be very easy…
Christian Metzler
  • 2,971
  • 5
  • 24
  • 30
7
votes
1 answer

Is there any Delphi version that can emit RTTI containing tkUnknown?

Just to make sure I'm not overlooking a strange edge case as I've found yet a case that produce it, but I want to make sure: Is there any Delphi version that can emit RTTI containing a type that has tkUnknown as TTypeKind? If so: any documentation…
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
7
votes
3 answers

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

Consider the following code: #include #include #include using namespace std; struct A { int data; }; struct B1 : A {}; struct B2 : virtual A {}; struct Base1 : virtual A {}; struct Base2 : virtual A {}; struct…
yeputons
  • 8,478
  • 34
  • 67
7
votes
2 answers

Does typeid(T) get evaluated at run time or compile time?

I cannot find the answer to this seemingly simple question anywhere. Does the following C++ function use RTTI? It certainly doesn't have to, but I was wondering if there is a guarantee that typeid will be determined at compile time. template…
Watusimoto
  • 1,773
  • 1
  • 23
  • 38