rtti

How can I distinguish TDateTime properties from Double properties with RTTI?

时光怂恿深爱的人放手 提交于 2019-12-03 22:41:33
Using the RTTI system in Delphi 2010, is there any way to find out if a property is a TDateTime? It's currently treating it as a double whenever I call back asVariant and also if I check the property type. Is this due to the fact it can only see the base type? (TDateTime = double) Try checking the Name property of the TRttiProperty.PropertyType I don't have Delphi 2010, but this works in XE. {$APPTYPE CONSOLE} uses SysUtils, Classes, Rtti; type TMyClass =class private FDate: TDateTime; FProp: Integer; FDate2: TDateTime; FDate1: TDateTime; public property Date1 : TDateTime read FDate1 Write

Delphi Rtti: how to get objects from TObjectList<T>

坚强是说给别人听的谎言 提交于 2019-12-03 17:11:18
I am working a custom class to xml converter and one of the requirements is the ability to stream TObjectList<T> fields. I am trying to invoke the ToArray() method to get hold of the TObjectlist's objects, but I get 'Invalid class typecast' because the types obviously don't match. take this class for example: type TSite = class Name : String; Address : String; end; TSites = class Sites : TObjecList<TSite>; end; I just need to get the Site Objects from the Sites TObjectList. Please keep in mind that I am using RTTI, so I don't know the ObjectType in TObjectList, so Typecasting won't work . This

Where are the Delphi Attributes Real World Examples?

霸气de小男生 提交于 2019-12-03 16:48:52
问题 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 code and could not understand how to implement it myself, not for DB, not for XML. So I've looked for all Google's results on Delphi Attributes and all that people post are declaration examples and then stops before even showing their examples in

how i can set the value of a nested property using the RTTI

旧巷老猫 提交于 2019-12-03 16:48:39
Check this simplified sample (the real scenario is different), I want to set tne value of a nested property of a object, in this case set the color of the Font for a TLabel component to clRed using RTTI. var p : TRttiProperty; p2: TRttiProperty; c : TRttiContext; begin c := TRttiContext.Create; try p := c.GetType(Label1.ClassInfo).GetProperty('Font'); p2 := c.GetType(p.PropertyType.Handle).GetProperty('Color'); p2.SetValue(p.PropertyType.AsInstance,clred); //this line is not working finally c.Free; end; end; also i tried p2.SetValue(Label1,clred); The following code will work. var p :

Difference between RTTI and reflection in Java

强颜欢笑 提交于 2019-12-03 15:00:57
My question is when how does the class info gets loaded during runtime? When someone calls instanceof is that considered RTTI or reflection? Or it depends on the actual situation? The term " RTTI " is a C++-specific term referring to the functionality of the core language that allows the program to determine the dynamic types of various objects at runtime. It usually refers to the dynamic_cast or typeid operators, along with the associated std::type_info object produced by typeid . The term reflection, on the other hand, is a generic term used across programming languages to refer to the

How can I get a dataset of in-memory objects?

青春壹個敷衍的年華 提交于 2019-12-03 12:51:46
Does anyone know of a TDataset descendant that works with Generics and RTTI, so that I can write code like this, and make use of data-aware components in the GUI? : ... ds:TDataset<TPerson>; ... procedure DoStuff; begin ds:=TDataset<TPerson>.create; ds.add(TPerson.Create('A.','Hitler',77)); ds.add(TPerson.Create('O.','Bin Laden',88)); end; This should be possible. The fielddefs can be created via RTTI because the exact type of the data is known. Values can also be automatically marshalled back and forth, so you can both view and edit data that's in a class or a record. I hate having to write a

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

橙三吉。 提交于 2019-12-03 10:04:57
问题 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: PTypeInfo; begin ... ctx := TRttiContext.Create; try o := GetLastClassInParams(ctx, obj, a, param_idx); tt := ctx.GetType(o.TypeInfo); if high(a) < param_idx then raise Exception.Create(S_FN + S_NOP); p := tt.GetProperty(a[param_idx]); if p = nil then raise Exception

Shrinking exe by removing RTTI

ⅰ亾dé卋堺 提交于 2019-12-03 08:38:23
In this question ( link ) it was said that the line below (in each unit) would remove as much RTTI as possible: {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} The posting didn't mention what Delphi version it works with, but I assume D2010. However, when I include the line above, I get this error: DCC Fatal Error: E2158 System unit out of date or corrupted: missing TVisibilityClasses. I'm using a "stock" version of D2010 and have never done anything that I'm aware of that would change the default installation or the libraries. Any suggestions? TIA Related question: link . Giel Make

Getting the Unit Name which belongs to any type (TRttiType)

微笑、不失礼 提交于 2019-12-03 07:50:15
I need to get the name of the unit (namespace) of any TRttiType . so far, I have tried the following. 1) using the PTypeData.UnitName , this solution works, but only when the TTypeKind is tkClass. procedure ListAllUnits; var ctx : TRttiContext; lType: TRttiType; Units: TStrings; begin Units:=TStringList.Create; try ctx := TRttiContext.Create; for lType in ctx.GetTypes do if lType.IsInstance then //only works for classes if Units.IndexOf(UTF8ToString(GetTypeData(lType.Handle).UnitName))<0 then Units.Add(UTF8ToString(GetTypeData(lType.Handle).UnitName)); Writeln(Units.Text); finally Units.Free;

Delphi - Invoke Record method per name

我的未来我决定 提交于 2019-12-03 07:25:46
I wrote a scriptlanguage for my applications and my goal is to make it possible to publish any type from delphi in the script. I use rtti to automatize this task. For any instance type like classes I use the following code to find and call a method from script. var Info : TRttiType; Meth : TRttiMethod; Param : TArray<TValue>; Result : TValue; AnyClass : TClass; begin ... Info := RttiContext.GetType(AnyClass); Meth := Info.GetMethod('AMethod'); Setlength(Param, 1); Param[0] := TValue.From<Integer>(11); Result := Meth.Invoke(ClassInstance, Param); ... end; But with a record this code doesn't