rtti

How to access record properties?

心不动则不痛 提交于 2019-12-02 14:10:51
问题 I need to access, record properties, and set/get this property values. Firstly, i want to access properties. But i can't. What is wrong? Ver : Delphi XE6. sample code: type TmyRecord = record private Str : String; public property StrProp :String read Str; end; procedure TForm1.Button3Click(Sender: TObject); var c : TRttiContext; t : TRttiType; field : TRttiField; prop : TRttiProperty; begin c := TRttiContext.Create; try Memo1.Lines.Append('Fields'); for field in c.GetType(TypeInfo(TMyRecord))

Remove classes string name from compiled release exe

我只是一个虾纸丫 提交于 2019-12-02 10:16:46
I compile the release version of my application project. When I look with binary editor my compiled final exe i can see all the class name of my own created object, for example : TPolygon, TRectangle, etc..., as binary text data inside the exe. How i can remove this information from exe. I try to remove disabling RTTI using in dpr: {$WEAKLINKRTTI ON} {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} But not luck, any hints. If you were to remove class names from the executable, then your application would stop working. The .dfm files that are compiled into your application contain the

Get a sub property of a component in Delphi using RTTI

前提是你 提交于 2019-12-02 09:09:39
问题 I would like to access the following property using RTTI MyComponent1.Property['variable'].SubProperty I would like something like that: var Ctx: TRttiContext; Typ: TRttiType; SubTyp: TRttiType; Prop: TRttiProperty; SubProp: TRttiProperty; begin Ctx:= TRttiContext.Create; Typ:= Ctx.GetType(MyComponent1.ClassInfo); Prop:= Typ.GetProperty('Property['variable'].Subproperty') //not possible Prop.SetValue(MyComponent1.Property['variable'],'500'); end; Basically I want to access a subproperty of my

How to get the type of the elements in a declared TList

夙愿已清 提交于 2019-12-02 09:00:53
I'd like to know if there is a way to get the type of the elements of a declared, but not instantiated, TList. I can capture the class of an object property like this: MyList: TList<TMyObject> read FMyList; MyRTTIProperty: TRttiProperty; NewObject: TObject; PropertyClass: TClass; MyRttiProperty := MyRttiType.GetProperty('MyList'); PropertyClass := MyRTTIProperty.PropertyType.Handle.TypeData.ClassType; // (returns TList<TMyObject>) NewObject := PropertyClass.Create; This way I can instantiate my list correctly. But now I also want to get the class of the elements, TMyObject, so that I can

return a Type, or how to preserve a type of an object pointer?

最后都变了- 提交于 2019-12-02 01:53:44
问题 I have a very complicated code structure, but the important bits are: typical setup: I have a base class and two classes that derive from this base class and each has own members, and which don't have a standard constructor class BaseSolver{ ... }; class SolverA : BaseSolver{ public: std::string a; SolverA(TypeA objectA); }; class SolverB : BaseSolver{ public: int b; SolverB(TypeB objectB); }; Now I have a config xml file from which I read whether I have to use SolverA or SolverB . Therefore

Delphi: RTTI for indexed properties in 2010?

…衆ロ難τιáo~ 提交于 2019-12-02 00:01:02
问题 Please forgive the verbosity of the following code example. Using Delphi 2009, I created the two classes TOtherClass and TMyClass: TOtherClass = class(TObject) public FData: string; end; TMyClass = class(TObject) private FIndxPropList: Array of TOtherClass; function GetIndxProp(Index: Integer): TOtherClass; procedure SetIndxProp(Index: Integer; Value: TOtherClass); public property IndxProp[Index: Integer]: TOtherClass read GetIndxProp write SetIndxProp; end; with access specifiers implemented

RTTI information for method pointer

不羁岁月 提交于 2019-12-01 22:09:08
Is it possible to obtain RTTI information about a TMethod ? I can get the instance by Instance := TObject(Method.Data); so I can get the RTTI type of the instance, but how can I get the correct TRttiMethod ? I want to check for attributes on a method passed in using a method pointer. This approach works in theory, and there's a good change it will work in practice, but there are a couple of things that could prevent you from getting hold of the TRttiMethod . The TMethod record says Data: Pointer , not TObject . This implies there might be a possibility of having something other then an TObject

return a Type, or how to preserve a type of an object pointer?

放肆的年华 提交于 2019-12-01 21:14:36
I have a very complicated code structure, but the important bits are: typical setup: I have a base class and two classes that derive from this base class and each has own members, and which don't have a standard constructor class BaseSolver{ ... }; class SolverA : BaseSolver{ public: std::string a; SolverA(TypeA objectA); }; class SolverB : BaseSolver{ public: int b; SolverB(TypeB objectB); }; Now I have a config xml file from which I read whether I have to use SolverA or SolverB . Therefore I have an IOService: template<class T> class IOService { BaseSolver* getSolver() { std::string

Delphi: how to set the length of a RTTI-accessed dynamic array using DynArraySetLength?

不打扰是莪最后的温柔 提交于 2019-12-01 20:36:57
I'd like to set the length of a dynamic array, as suggested in this post . I have two classes TMyClass and the related TChildClass defined as TChildClass = class private FField1: string; FField2: string; end; TMyClass = class private FField1: TChildClass; FField2: Array of TChildClass; end; The array augmentation is implemented as var RContext: TRttiContext; RType: TRttiType; Val: TValue; // Contains the TMyClass instance RField: TRttiField; // A field in the TMyClass instance RElementType: TRttiType; // The kind of elements in the dyn array DynArr: TRttiDynamicArrayType; Value: TValue; //

Delphi RTTI unable to find interface

坚强是说给别人听的谎言 提交于 2019-12-01 20:10:45
问题 I'm trying to fetch an interface using D2010 RTTI. program rtti_sb_1; {$APPTYPE CONSOLE} {$M+} uses SysUtils, Rtti, mynamespace in 'mynamespace.pas'; var ctx: TRttiContext; RType: TRttiType; MyClass: TMyIntfClass; begin ctx := TRttiContext.Create; MyClass := TMyIntfClass.Create; // This prints a list of all known types, including some interfaces. // Unfortunately, IMyPrettyLittleInterface doesn't seem to be one of them. for RType in ctx.GetTypes do WriteLn(RType.Name); // Finding the class