rtti设置record的值
rtti设置record的值
uese system.rtti;
class procedure Trows.scan<T>(const aRec: T; instance: Pointer; ds: TDataSet); begin var rtx: TRttiContext := TRttiContext.Create; var rt: TRttiType := rtx.GetType(TypeInfo(T)); if (rt = nil) then Exit; for var rf: TRttiField in rt.AsRecord.GetFields do rf.SetValue(instance, ds.FieldByName(rf.Name).AsString); rtx.Free; end;
调用演示
var i: Integer := 0; db.qry.First; while not db.qry.Eof do begin Trows.scan<Tdanwei>(data.rows[i], @data.rows[i], db.qry); db.qry.Next; Inc(i); end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/17645672.html