rtti

How can I get an enumeration's valid ranges using RTTI or TypeInfo in Delphi

佐手、 提交于 2021-02-07 08:31:54
问题 I am using RTTI in a test project to evaluate enumeration values, most commonly properties on an object. If an enumeration is out of range I want to display text similar to what Evaluate/Modify IDE Window would show. Something like "(out of bound) 255". The sample code below uses TypeInfo to display the problem with a value outside the enumeration as an Access Violation when using GetEnumName . Any solution using RTTI or TypeInfo would help me, I just don't know the enumerated type in my test

How do I instantiate a class from its TRttiType?

自古美人都是妖i 提交于 2021-02-06 11:09:49
问题 I want to create a form given its class name as a string, which has been asked about before, but instead of calling GetClass , I want to use Delphi's new RTTI feature. With this code, I've got a TRttiType , but I don't know how to instantiate it. var f:TFormBase; ctx:TRttiContext; lType:TRttiType; begin ctx := TRttiContext.Create; for lType in ctx.GetTypes do begin if lType.Name = 'TFormFormulirPendaftaran' then begin //how to instantiate lType here? Break; end; end; end; I've also tried

How do I instantiate a class from its TRttiType?

时间秒杀一切 提交于 2021-02-06 11:05:05
问题 I want to create a form given its class name as a string, which has been asked about before, but instead of calling GetClass , I want to use Delphi's new RTTI feature. With this code, I've got a TRttiType , but I don't know how to instantiate it. var f:TFormBase; ctx:TRttiContext; lType:TRttiType; begin ctx := TRttiContext.Create; for lType in ctx.GetTypes do begin if lType.Name = 'TFormFormulirPendaftaran' then begin //how to instantiate lType here? Break; end; end; end; I've also tried

Is it possible to use Attributes on Delphi method arguments?

為{幸葍}努か 提交于 2021-02-06 08:57:13
问题 Is this valid code with newer Delphi versions? // handle HTTP request "example.com/products?ProductID=123" procedure TMyRESTfulService.HandleRequest([QueryParam] ProductID: string); In this example, the argument "ProductID" is attributed with [QueryParam] . If this is valid code in Delphi, there must also be a way to write RTTI based code to find the attributed argument type information. See my previous question Which language elements can be annotated using attributes language feature of

Is it possible to use Attributes on Delphi method arguments?

£可爱£侵袭症+ 提交于 2021-02-06 08:56:24
问题 Is this valid code with newer Delphi versions? // handle HTTP request "example.com/products?ProductID=123" procedure TMyRESTfulService.HandleRequest([QueryParam] ProductID: string); In this example, the argument "ProductID" is attributed with [QueryParam] . If this is valid code in Delphi, there must also be a way to write RTTI based code to find the attributed argument type information. See my previous question Which language elements can be annotated using attributes language feature of

Is it possible to use Attributes on Delphi method arguments?

扶醉桌前 提交于 2021-02-06 08:55:24
问题 Is this valid code with newer Delphi versions? // handle HTTP request "example.com/products?ProductID=123" procedure TMyRESTfulService.HandleRequest([QueryParam] ProductID: string); In this example, the argument "ProductID" is attributed with [QueryParam] . If this is valid code in Delphi, there must also be a way to write RTTI based code to find the attributed argument type information. See my previous question Which language elements can be annotated using attributes language feature of

Is it possible to use Attributes on Delphi method arguments?

走远了吗. 提交于 2021-02-06 08:55:01
问题 Is this valid code with newer Delphi versions? // handle HTTP request "example.com/products?ProductID=123" procedure TMyRESTfulService.HandleRequest([QueryParam] ProductID: string); In this example, the argument "ProductID" is attributed with [QueryParam] . If this is valid code in Delphi, there must also be a way to write RTTI based code to find the attributed argument type information. See my previous question Which language elements can be annotated using attributes language feature of

Android NDK + Two Shared Libraries + RTTI + Dynamic cast = Impossible

心不动则不痛 提交于 2021-01-29 14:26:28
问题 I've been at this for 4 hours so far on a Sunday. I'm about to give up. I've tried literally every post I've found on the internet and this simply will..not..work! Any instance of dynamic_cast with references or pointers either returns null or flat-out crashes my program. This is absolutely 100% critical to my entire application architecture, and I may just have to go to 200 MB static libs if I can't get this going. I'm building with -frtti (there's no -fno-rtti), and linking with -Wl,-export

Is there a way to get GUID from a generic constraint type?

喜夏-厌秋 提交于 2021-01-28 06:42:38
问题 In the sample code below, the Run<T>() displays the values of GUID IFoo and IFoo<T> interfaces: type IBar = interface ['{992E6597-42F1-40F8-B678-C4A86864B030}'] end; IFoo = interface ['{0C589AF8-5727-4EAA-BB41-6D51D70B9D35}'] end; IFoo<T> = interface(IFoo) ['{8FF54F6B-0896-4EA3-85F8-66BA70F9D2DA}'] end; TTest = class public class procedure Run<T: IFoo>; end; class procedure TTest.Run<T>; var LContext: TRttiContext; IFoo_T_TypeInfo: PTypeInfo; IFooTypeInfo: PTypeInfo; begin IFoo_T_TypeInfo :=

Delphi: invoke constructor raises EInvalidCast

橙三吉。 提交于 2021-01-27 06:53:54
问题 I'm trying to invoke a constructor obtained via RTTI (running D2010 version 14.0.3593.25826). The constructor takes a mixture of strings and objects as its arguments, all of which should be initialized to '' or nil . (Disclaimer: I know that the desired constructor will be the one with maximum number of parameters, hence the weird-looking, although suboptimal design.) The code goes as follows: program sb_rtti; {$APPTYPE CONSOLE} uses RTTI, TypInfo, SysUtils; type TMyClass = class (TObject)