在Delphi 2010中使用RTTI系统,有没有办法找出属性是否是TDateTime?当我回调为Variant时,如果我检查属性类型,它现在将其视为双精度。这是因为它只能看到基本类型吗? (TDateTime = double)
解决方法
尝试检查
TRttiProperty.PropertyType
的Name属性
我没有德尔福2010,但这在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 FDate1; property Prop : Integer read FProp Write FProp; property Date2 : TDateTime read FDate2 Write FDate2; end; var ctx : TRttiContext; t : TRttiType; p : TRttiProperty; begin ctx := TRttiContext.Create; try t := ctx.GetType(TMyClass.ClassInfo); for p in t.GetProperties do if CompareText('TDateTime',p.PropertyType.Name)=0 then Writeln(Format('the property %s is %s',[p.Name,p.PropertyType.Name])); finally ctx.Free; end; Readln; end.
这个代码返回
the property Date1 is TDateTime the property Date2 is TDateTime
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。