Request for RTTT TValue: implement TValue.IsType<T>
Original Reporter info from Mantis: Thaddy
-
Reporter name: Thaddy de Koning
Original Reporter info from Mantis: Thaddy
- Reporter name: Thaddy de Koning
Description:
While experimenting with some Delphi RTTI examples I had to write a typehelper to get the following code working:
http://robstechcorner.blogspot.com/2009/09/introduction-to-tvalue.html
Steps to reproduce:
Try this example from robstechcorner, it does not compile:
program Project10;
{$IFDEF FPC}{$MODE DELPHI}
{$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
uses
Rtti,TypInfo;
var
v : TValue;
i : Integer;
begin
i := 10;
v := I;
Writeln('V.Kind =',GetEnumName(TypeInfo(TTypeKind),ord(v.Kind)));
Writeln('V.IsType<Integer> = ',v.IsType<Integer>);
Writeln('V.IsType<TObject> = ',v.IsType<TObject>);
Writeln('V.IsObject = ',v.IsObject);
readln;
end.
Additional information:
temporary solved it like this:
program Project10;
{$mode delphi}
uses
Rtti,TypInfo;
type
TValueHelper = record helper for TValue
function IsType<T>:Boolean;
end;
function TValueHelper.IsType<T>:Boolean;
begin
Result := self.Kind = PTypeInfo(system.TypeInfo(T)).Kind;
end;
var
v : TValue;
i : Integer;
begin
i := 10;
v := I;
Writeln('V.Kind =',GetEnumName(TypeInfo(TTypeKind),ord(v.Kind)));
Writeln('V.IsType<Integer> = ',v.IsType<Integer>);
Writeln('V.IsType<TObject> = ',v.IsType<TObject>);
Writeln('V.IsObject = ',v.IsObject);
readln;
end.
Mantis conversion info:
- Mantis ID: 36294
- Build: 43449
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 43591 (#d98e5518)