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
6
votes
1 answer

How best to expose a class instance in DWScript

I am putting together a built-in script capability using the excellent Pascal DWScript. I have also add my own Delphi-side class definition (TDemo) to DWScript using: dwsUnit.ExposeRTTI( TDemo.ClassInfo ) This just works and is a great way of…
Brian Frost
  • 13,334
  • 11
  • 80
  • 154
6
votes
3 answers

How do I create a generic TValue for enumerated RTTI field?

In the question here a method for creating a compatible TValue to use with SetValue is shown. I'm trying to make a generic version of this, to use RTTI to store a class into an INI file. This is my cut down code: procedure TMyClass.LoadRTTI(xObject:…
mj2008
  • 6,647
  • 2
  • 38
  • 56
6
votes
2 answers

How to avoid virtual inheritance in C++17?

Let's see example classes. Base class is ITransport, transport class interface: class ITransport { public: virtual void move(const Path& p) = 0; virtual double estimateTime(const Path& path) = 0; /*Some more…
6
votes
2 answers

Bug with RTTI TRttiMethod.Invoke, stdcall and const parameters

I have a problem with RTTI TRttiMethod.Invoke, stdcall and const parameters: obj := TClassRecordTest.Create; try b.a := 10; b.b := 100; a.a := 1; a.b := 2; writeln('b.a='+IntToStr(b.a)+' b.b='+IntToStr(b.b)); …
Mielofon
  • 428
  • 3
  • 14
6
votes
3 answers

Java polymorphism and downcasting

I am playing with Java's reflection API, and I'm writing methods that inspect a given object and describes its fields, methods, and so on. I am using the getFields() method to iterate on the different attributes and display the object…
executifs
  • 1,138
  • 1
  • 9
  • 23
6
votes
2 answers

Delphi Rtti for interfaces in a generic context

for a framework I wrote a wrapper which takes any object, interface or record type to explore its properties or fields. The class declaration is as follows: TWrapper = class private FType : TRttiType; FInstance : Pointer; {...} public …
Christian Metzler
  • 2,971
  • 5
  • 24
  • 30
6
votes
4 answers

Will multiple calls to typeid(T).name() return the same pointer?

In C++ I can use typeid operator to retrieve the name of any polymorphic class: const char* name = typeid( CMyClass ).name(); The string pointed to by the returned const char* will be available to my program for as long as the corresponding class…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
6
votes
1 answer

Java: instanceof vs class name switch performance

I was interested in performance question about determine type of object and write some benchmarks with 2 ways of determination. Can someone explain me why variant with instanceof faster 350 times than variant with class name switching with…
mikewoe
  • 270
  • 2
  • 12
6
votes
2 answers

What's the benefit of implement interface at runtime?

I'm trying to understand TVirtualInterface class. {$APPTYPE CONSOLE} uses SysUtils, Rtti; type ISpecificInterface = interface(IInvokable) ['{281D8B97-397E-430A-895A-9CA4E1F5FB5F}'] procedure SpecificProcedure; end; procedure…
İsmail Kocacan
  • 1,204
  • 13
  • 38
6
votes
2 answers

Polymorphically catching an exception in a -fno-rtti shared library on Mac OS X

I'm building a shared library with f-no-rtti. Internally, this library throws std:invalid_argument and catches std::exception, but the catch clause is never entered. The following code reproduces the problem (g++ 4.2, Mac OS X 10.6): // library.cpp:…
Pedro d'Aquino
  • 5,130
  • 6
  • 36
  • 46
6
votes
1 answer

Delphi 2010 RTTI and Interface fields

I have a problem with the properties of IInterface type. I don't know how to assign values to these properties using RTTI Here's an example:. program Project2; uses Forms, RTTI, Windows, TypInfo; {$R *.res} type ITestInterfacedClass =…
Mielofon
  • 428
  • 3
  • 14
6
votes
1 answer

FreePascal RTTI. Is there a way to invoke method?

I'm trying to find out if there is a way to do things similar to Delphi's enhanced RTTI features. As far as I know FPC doesn't provide RTTI features which appeared in Delphi since Delphi 2010. But I'd like to find some way to do a few tricks during…
Int0h
  • 71
  • 5
6
votes
1 answer

Using RTTI with objects derived from an external library

I am working with an external library and need to create an observer pattern where observers are derived from an object that belongs to the library. I do not want to change the base class from the library and at the same time I have to use the list…
6
votes
1 answer

How do I use a string in TRttiMethod.Invoke as parameter properly?

I'm trying to generalize the content validation of visual components with the Text-property using RTTI but when I try to pass a string value into TRttiMethod.Invoke, I get the Message "Invalid Typecast". (Actually "Ungültige Typumwandlung" but I…
S. Langhammer
  • 135
  • 1
  • 1
  • 7
6
votes
2 answers

Getting the string name of an interface using Delphi RTTI

I have proved that I can get the name of an interface from its GUID using Delphi 2010 (eg IMyInterface converted to the string 'IMyInterface'. I'd like to achieve this in Delphi 7 (for compatibility). Is this possible? Or are there fundamental…
Brian Frost
  • 13,334
  • 11
  • 80
  • 154