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

Can we use RTTI to find functions/procedures by name and run them?

As we can find a Property or an Object using RTTI, can we search for a certain function or procedure (not from an object as a method but from an unit) loaded in memory knowing just it's name? And if we can, is it possible to execute it sending it's…
NaN
  • 8,596
  • 20
  • 79
  • 153
7
votes
1 answer

How can I set/get property value through RTTI for complex things like TStringGrid.Cells?

I have values stored in xml and lua code and accessing object's properties through RTTI. var o, v: TValue; // o is current object a: TStringDynArray; // params as array ctx: TRttiContext; tt: TRttiType; p: TRttiProperty; pt:…
user2091150
  • 978
  • 12
  • 25
7
votes
2 answers

Discovering the class where a property is first published with multiple levels of inheritance

Using the Typinfo unit, it is easy to enumerate properties as seen in the following snippet: procedure TYRPropertiesMap.InitFrom(AClass: TClass; InheritLevel: Integer = 0); var propInfo: PPropInfo; propCount: Integer; propList: PPropList; …
Atorian
  • 777
  • 10
  • 26
7
votes
1 answer

How to get access field in Delphi using RTTI?

Consider the following: TFieldType = class fValue: string; end; TMainClass = class private Ffield: TFieldType; public function GetValue: string; end; In TMainClass.GetValue I'm tryin get values of TMainClass fields: function…
boombastic
  • 85
  • 1
  • 5
7
votes
3 answers

C++11 Dynamic Cast If Else Chain -> Switch

Consider the following: struct B { }; template struct D : B { T t; } void g(int i) { ... } void g(string s) { ... } void g(char c) { ... } void f(B* b) { if (dynamic_cast*>(b)) { …
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
7
votes
1 answer

warning message RTTI symbol not found when using boost::iostreams

I use Boost::iostreams to write simultaneously to my console and a file. When i use eclipse to debug(with gdb of course), i receive a warning which says RTTI symbol not found for one of the classes that i am using from Boost::iostreams. Here is the…
hAcKnRoCk
  • 1,118
  • 3
  • 16
  • 30
7
votes
2 answers

Can "unused" classes be made available in Delphi XE

I'm working in Delphi XE, windows 7. In an application I want to enable different report types for my users to select. To do this, I have 1 base report class and a subclass per report type (xml, csv, ppt, etc). {Just an illustrating…
deColaman
  • 213
  • 2
  • 14
7
votes
3 answers

Delphi RTTI: Get property's class

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…
David Cornelius
  • 437
  • 1
  • 5
  • 12
7
votes
2 answers

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

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…
conciliator
  • 6,078
  • 6
  • 41
  • 66
6
votes
1 answer

Error while trying to access class attributes

I have this class: {$RTTI EXPLICIT FIELDS([vcProtected]) PROPERTIES([vcProtected])} const PP_VEHICLE_FIELD = 'VEICULO_ID'; PP_DRIVER_FIELD = 'MOTORISTA_ID'; PP_TRIP_FIELD = 'VIAGEM_ID'; PP_DATE = 'DATA'; type [TAttrDBTable('NONE')] …
Rodrigo Farias Rezino
  • 2,687
  • 3
  • 33
  • 60
6
votes
4 answers

String representation of the content type of a Variant?

First, apologies for my English, I hope it makes sense what I`ve written here. Now to my problem. How can I get the string representation of the content type of a Variant using TypInfo.GetEnumName(). I have tried the following, without luck, I get a…
Alin Sfetcu
  • 542
  • 6
  • 16
6
votes
1 answer

How I can get the element type of an array using RTTI

I'm using this code to get the element type of an array {$APPTYPE CONSOLE} uses Rtti, SysUtils; type TFooArray= array of TDateTime; Var T : TRttiType; begin try T:=TRttiContext.Create.GetType(TypeInfo(TFooArray)); …
Salvador
  • 16,132
  • 33
  • 143
  • 245
6
votes
2 answers

How to check if a Delphi class is declared abstract?

Is it possible in Delphi to use RTTI (or something else) to check if a class is declared as abstract? Something like: TMyAbstractClass = class abstract(TObject) // ... end; ... if IsAbstract(TMyAbstractClass.ClassInfo) then …
mrMoo
  • 91
  • 1
  • 5
6
votes
3 answers

Accesing a strict private field using the RTTI

consider this simple code {$APPTYPE CONSOLE} uses Rtti, SysUtils; type {$M+} TFoo = class strict private class var Field1 : Integer; field2 : Integer; private field3 : Integer; class var Field4 : Integer; …
Salvador
  • 16,132
  • 33
  • 143
  • 245
6
votes
1 answer

Losing RTTI info after returning from a function

Given a class and subclass: class Event {...} class Note : public Event {...} A Note is Cloned and stored in a pointer within a function f(). The type-information is preserved in the pointer and can be recovered by dynamic_cast: void f() { …
Christof Schardt
  • 551
  • 1
  • 5
  • 16