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;
标签:rt,db,record,设置,var,qry,rtti,rtx From: https://www.cnblogs.com/hnxxcxg/p/17645672.html