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
14
votes
4 answers

Delphi: Prevent method names from appearing in executables

I am writing a class to handle security in my executable (checking serials, trial date check etc). After I compile the executable (even in Release build, with all debug and RTTI generation turned off), when I open it in NotePad and search the method…
Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156
14
votes
3 answers

Where are the Delphi Attributes Real World Examples?

I know by TMS Aurelius that we can use the "new" 2010 attributes feature to serialize database table fields into object properties at run-time, for example, and I am not an expert on this deep object oriented schema, so I look into the TMS source…
NaN
  • 8,596
  • 20
  • 79
  • 153
14
votes
1 answer

How I make RTTI-call with safecall function method of interface?

I have this test program https://gist.github.com/real-mielofon/5002732 RttiValue := RttiMethod.Invoke(RttiInstance, [10]); and simple unit with interface: unit Unit163; interface type {$M+} ISafeIntf = interface function TestMethod(aI:…
Mielofon
  • 428
  • 3
  • 14
14
votes
2 answers

How to loop all properties in a Class

I have a class in my Delphi app where I would like an easy and dynamic way of resetting all the string properties to '' and all the boolean properties to False As far as I can see on the web it should be possible to make a loop of some sort, but how…
OZ8HP
  • 1,443
  • 4
  • 31
  • 61
13
votes
3 answers

How can I convert from generic to Variant in Delphi

I have a Delphi generic class that exposes a function with an argument of the generic type. Inside this function, I need to pass an instance of the generic type on to another object expecting a Variant type. Similar to this: type IMyInterface =…
Mathias Falkenberg
  • 1,110
  • 1
  • 11
  • 25
13
votes
1 answer

How to get the list of classes derived from a given class, with enhanced RTTI?

I need to get a list of form types, but only for types derived from a given base form. I use Delphi 2010 and enhanced RTTI to browse types My current code is: rc := TRTTIContext.Create; rtyps := rc.GetTypes; for rtyp in rtyps do begin if…
user315561
  • 651
  • 5
  • 18
13
votes
4 answers

How do I typecast with type_info?

I've stored a pointer to a type_info object. int MyVariable = 123; const std::type_info* Datatype = &typeid(MyVariable); How might I use this to typecast another variable to that type? I tried this, but it doesn't work: std::cout <<…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
13
votes
1 answer

Delphi XE6 DLL: Unwanted export: TMethodImplementationIntercept

When you compile a DLL in Delphi XE6, it automatically exports the function TMethodImplementationIntercept from System.Rtti.pas. I tried to find a way to avoid this export but didn't find any configuration or compiler directive that could do the…
karliwson
  • 3,365
  • 1
  • 24
  • 46
13
votes
4 answers

Duplicating components at Run-Time

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…
Atlas
  • 1,353
  • 5
  • 19
  • 32
13
votes
7 answers

Delphi 2010 RTTI : Explore Enumerations

Considering such an enumeration : type TTypeOfData = ( [XmlName('ABC')] todABC, [XmlName('DEF')] todDEF, [XmlName('GHI')] todGHI ); Where XmlName is a custom attribute used to define the serialization string for members of this…
ZeDalaye
  • 689
  • 7
  • 17
13
votes
3 answers

Class identity without RTTI

I've found a simple solution somewhere on the internet to an identity class without built-in C++ RTTI. template class Identity { public: static int64_t id() { static int64_t dummy; return…
pproger
  • 347
  • 1
  • 2
  • 9
12
votes
0 answers

Why `std::invalid_argument` is not caught with no-rtti in macOS M1 environment?

Today I met a weird behaviour in catching exceptions in C++, could anyone clarify it to me? Code snippe #include #include #include int main() { try { std::stod("notanumber"); } catch (const…
12
votes
2 answers

When can typeid return different type_info instances for same type?

Andrei Alexandrescu writes in Modern C++ Design: The objects returned by typeid have static storage, so you don't have to worry about lifetime issues. Andrei continues: The standard does not guarantee that each invocation of, say,…
dalle
  • 18,057
  • 5
  • 57
  • 81
11
votes
4 answers

How to get the typeid of a void* pointer?

I have a list of pointers to objects. These objects have nothing in common (i.e. no common base class); for better understanding: It is a list of objects that lie under the mouse cursor in a GUI. Now I would like to know what kind of object it is. A…
Simon A. Eugster
  • 4,114
  • 4
  • 36
  • 31
11
votes
2 answers

How to use Delphi RTTI to get and set Record Values

I'm attempting to use the enhanced RTTI features in Delphi XE or later, to read and write objects to XML. So far I've been successful with integers, floats, strings, enumerated types, sets and classes but can't output or read records correctly. The…
Mitch
  • 335
  • 1
  • 3
  • 10