rtti

Is there a relation between RTTI and exceptions?

南笙酒味 提交于 2019-11-30 08:51:00
I remember coding on platforms that had both RTTI and exceptions disabled, and on others that had them both enabled. However, I cannot remember coding on a platform that would enable one and disable the other one. Is there any kind of dependency between the two concepts? Said differently, do exceptions need RTTI to function? Or the contrary? No, Exceptions do not need RTTI functionality neither vice versa both are separate features. Some of the implementations might allow you to disable exceptions(-fnoexceptions in gcc) but I don't know of any implementation which needs RTTI for exceptions or

Problems throwing and catching exceptions on OS X with -fno-rtti

余生颓废 提交于 2019-11-30 08:15:37
The issue is somewhat similar to this question but the accepted answer does not really propose a solution or workaround. In our project, we have a dylib and the main executalble. The dylib is compiled with -fno-rtti , while the executable does use RTTI. The problem happens when an exception (e.g. std::bad_alloc ) is thrown from the dylib and is caught in the exe. (Before you yell "exceptions need RTTI so you must have it on!", please note that the RTTI necessary for exceptions is always generated regardless of the -frtti or -fno-rtti setting. This is actually documented in the -fno-rtti flag

dynamic_cast with RTTI disabled

≡放荡痞女 提交于 2019-11-30 07:51:16
问题 I'm curious to know what happens when compiling code with a dynamic cast whith RTTI disabled (either with -fno-rtti on GCC or with /GR- on visual studio). Does the compiler "falls back" to static_cast ? Since (at least on VS) it does only issue a warning, what will the compiled code do ? More specifically, what bad things could happen if I compile without RTTI a code where I'm sure that there are no error possible with dynamic_cast (i.e. where dynamic_cast could be safely replaced by a static

No RTTI but still virtual methods

喜你入骨 提交于 2019-11-30 06:45:47
C++ code can be compiled with run-time type information disabled, which disables dynamic_cast . But, virtual (polymorphic) methods still need to be dispatched based on the run-time type of the target. Doesn't that imply the type information is present anyway, and dynamic_cast should be able to always work? Disabling RTTI kills dynamic_cast and typeid but has no impact on virtual functions. Virtual functions are dispatched via the "vtable" of classes which have any virtual functions; if you want to avoid having a vtable you can simply not have virtual functions. Lots of C++ code in the wild can

Rtti accessing fields and properties in complex data structures

扶醉桌前 提交于 2019-11-30 02:28:14
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 in case of a simple class with only basic member types (like e.g. integers or strings). But what if we have structured field types? Here is an example: TIntArray = array [0..1] of Integer; TPointArray = array [0..1] of Point; TExampleClass = class private FPoint : TPoint; FAnotherClass : TAnotherClass; FIntArray : TIntArray; FPointArray :

How to create an instance of object with RTTI in Delphi 2010?

人走茶凉 提交于 2019-11-30 02:01:53
As we all known, when we call a constructor of a class like this: instance := TSomeClass.Create; The Delphi compiler actually do the following things: Call the static NewInstance method to allocate memory and initialize the memory layout. Call the constructor method to perform the initialization of the class Call the AfterConstruction method It's simple and easy to understand. but I'm not very sure how the compiler handle exceptions in the second and the third step. It seems there are no explicit way to create an instance using a RTTI constructor method in D2010. so I wrote a simple function

How to use Delphi RTTI to get and set Record Values

陌路散爱 提交于 2019-11-30 00:48:29
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 problem seems to be getting an instance (pointer) to the record property. //Outputs Properties To XML procedure TMyBase.SaveToXML(node: TJclSimpleXMLElem); var child , subchild : TjclSimpleXMLElem ; FContext : TRttiContext ; FType : TRttiType ; FProp : TRttiProperty ; Value : TValue ; MyObj : TMyBase ; FField : TRttiField ; FRecord : TRttiRecordType

What's a good way to serialize Delphi object tree to XML--using RTTI and not custom code?

北城以北 提交于 2019-11-29 21:06:36
What's a good way to serialize a Delphi object tree to XML--using RTTI and not custom code? I would have loved to find that this feature is already built into Delphi, but it doesn't seem to be. I've found a few components (posted, below) that seem like they might perform this function. Have you used any of them or some other offering? Have you built your own? Am I missing something obvious, in Delphi? You can use the JVCL TJvAppXMLFileStorage component to serialize TPersistent derived classes. uses JvAppXMLStorage; var Storage: TJvAppXMLFileStorage; begin Storage := TJvAppXMLFileStorage.Create

TRTTIContext multi-thread issue

做~自己de王妃 提交于 2019-11-29 18:17:17
问题 Everything I've read indicates that TRTTIContext is thread-safe. However, TRTTIContext.FindType seems to fail (returns nil) occasionally when multithreading. Using a TCriticalSection around it fixes the issue. Note that I'm using XE6, and the issue doesn't seem to exist in XE. Edit: Seems to exist in all Delphi editions that have the new RTTI units. I've worked up a test project you can use to see for yourself. Create a new VCL project, drop a TMemo and a TButton, replace unit1 with below,

What is `type_info::before` useful for?

北城以北 提交于 2019-11-29 17:34:51
问题 According to cplusplus.com, the std::type_info::before() function... Returns true if the type precedes the type of rhs in the collation order. The collation order is just an internal order kept by a particular implementation and is not necessarily related to inheritance relations or declaring order. So what is it useful for? 回答1: Consider you want to put your type_info objects as keys into a map<type_info*, value> . The type_info doesn't have an operator < defined, so you must provide your