rtti

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

拈花ヽ惹草 提交于 2019-12-17 16:47:16
问题 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 reflection, or store array of pointers). Anyway, any help will be appreciated. Thanks! 回答1: First of all you can't use Delphi's RTTI for that purpose, because Delphi 7's RTTI only covers published members of classes. Even if you were on Delphi XE, there's

delphi xe disable RTTI

故事扮演 提交于 2019-12-17 12:34:12
问题 i have use delphi xe recently but exe size is very big because of rtti(i think) howto remove rtti , and can i make my application size as small as delphi 2009 application(490 kb) without comprssion; and what is the use of rtti 回答1: In short (full story provided by links in the splash's answer): {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} Note that as of XE6 and newer, this needs to be in each individual unit for which you want to disable RTTI. Before that (XE5 and below) it could

Accessing protected event of TWinControl

馋奶兔 提交于 2019-12-17 10:09:06
问题 imagine, you want to assign your own event procedure: procedure TSuperObject.DoSomething(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ShowMessage('Yes, I am doing'); end; to any TWinControl on the form. Normally if you have Panel1 (TPanel) on the form, you can do it easy: Panel1.OnMouseDown:=SuperObject1.DoSomething; But if you want to do it universally, how can it be accomplished? You can not access protected members of TWincontrol, so intuitive answer:

How expensive is RTTI?

人盡茶涼 提交于 2019-12-17 03:21:41
问题 I understand that there is a resource hit from using RTTI, but how big is it? Everywhere I've looked just says that "RTTI is expensive," but none of them actually give any benchmarks or quantitative data reguarding memory, processor time, or speed. So, just how expensive is RTTI? I might use it on an embedded system where I have only 4MB of RAM, so every bit counts. Edit: As per S. Lott's answer, it would be better if I include what I'm actually doing. I am using a class to pass in data of

Spark 2.x scala 2.1.1 custom encoder class type mismatch

China☆狼群 提交于 2019-12-14 04:06:41
问题 I am using this code to define an encoder for spark 2.x, in scala 2.1.1: import org.apache.spark.sql.Encoder import org.apache.spark.sql.types.StructType class LogProcessorMessageEncoder extends Encoder[LogProcessorMessage] { override def schema: StructType = null override def clsTag: Class[LogProcessorMessage] = classOf[LogProcessorMessage] } object LogProcessorMessage {} class LogProcessorMessage extends Serializable {} And IntelliJ says it is fine, but the override of the clsTag method

Enumerating published properties and subproperties in Delphi

我只是一个虾纸丫 提交于 2019-12-14 01:40:57
问题 Apologies if the question was asked before. I have some definition of some components as follows (please guide me if it's wrong, because I'm a beginner). What I am trying, is to enumerate all published properties of the derived components, particularly the sub-properties. I am able to enumerate the names of the properties, however, is it possible to enumerate the published properties for which I can access the elements (as in the sub-properties) during the execution of the program? something

Get constant fields from a class using RTTI

大憨熊 提交于 2019-12-12 17:19:28
问题 Can I enumerate the constants(const) from a class? I have tried MyClass = class const c1 = 'c1'; c2 = 'c2'; c3 = 'c3'; end; procedure GetConst(); var ctx: TRttiContext; objType: TRttiType; field: trttifield; s: string; begin ctx := TRttiContext.Create; objType := ctx.GetType(MyClass.ClassInfo); for field in objType.GetDeclaredFields do s:= field.Name; end; I would like to get c1, c2, c2. Is this possible? edit: what I want to do is define some keys for some external symbols(for a cad program)

Implementation of RTTI using typeid

早过忘川 提交于 2019-12-12 16:34:17
问题 I am a newbie in the study of advanced C++ topics so please pardon me if the question sounds too obvious. I have been reading about the various methods by which we can get the information of the type of the object at runtime in C++, which is generally referred to as RTTI. But, I am confused as to how does it work. I have read some of things that are often mentioned when RTTI is being explained. One of them is the use of dynamic_cast<> to cast an object to some other object dynamically.

What's the lifetime of the object returned by typeid operator?

回眸只為那壹抹淺笑 提交于 2019-12-12 11:16:58
问题 If I call typeid and retrieve the address of returned type_info : const type_info* info = &( typeid( Something ) ); what's the lifetime of the object returned by typeid and how long will the pointer to that object remain valid? 回答1: However the implementation implements them, the results of typeid expressions are lvalues and the lifetime of the objects that those lvalues refer to must last until the end of the program. From ISO/IEC 14882:2003 5.2.8 [expr.typeid]: The result of a typeid

Streamlined way to do C# run-time type identification that avoids a NULL check?

微笑、不失礼 提交于 2019-12-12 09:56:45
问题 I find myself using a common run-time type identification pattern, especially when writing code that handles controls of varying types. Here is the pattern: if (ctrl is ControlTypeEtc) (ctrl as ControlTypeEtc).SomeMethod(); I do this to avoid having to do a NULL check in case the as operator returns NULL. Is there a way to streamline this to a single operation? 回答1: No way to do this in a single operation. However, using as and checking for null is cheaper as there is only one case instead of