var
Contexto: TRttiContext;
TypObj: TRttiType;
Prop: TRttiProperty;
strInsert, strFields: String;
Atributo: TCustomAttribute;
PK: string;
q: TZQuery;
begin
strInsert := '';
strFields := '';
PK := getFieldPKRTTI(Obj.ClassType);
strInsert := 'SELECT * FROM ' + getTableNameRTTI(Obj.ClassType) +
' WHERE ' + PK + ' = ' + ID.ToString ;
q := Conexao.getQuery(strInsert);
q.Open;
Contexto := TRttiContext.Create;
TypObj := Contexto.GetType(Obj.ClassInfo);
for Prop in TypObj.GetProperties do begin
for Atributo in Prop.GetAttributes do begin
t := 0;
if Atributo is TIntegerCampo then
begin
t := q.FieldByName(TIntegerCampo(Atributo).NomeCampo).AsInteger;
Prop.SetValue(PByte(Obj),t);
end;
if Atributo is TOutroCampo then
begin
case TOutroCampo(Atributo).TipoCampo of
ftBoolean:
begin
t := q.FieldByName(TOutroCampo(Atributo).NomeCampo).AsString;
Prop.SetValue(PByte(Obj),t);
end;
ftBlob, ftString:
begin
t := q.FieldByName(TOutroCampo(Atributo).NomeCampo).AsString;
Prop.SetValue(PByte(Obj),t);
end;
ftFloat, ftCurrency:
begin
t := q.FieldByName(TOutroCampo(Atributo).NomeCampo).AsFloat;
Prop.SetValue(PByte(Obj),t);
end;
ftDate:
begin
t := q.FieldByName(TOutroCampo(Atributo).NomeCampo).AsDateTime;
Prop.SetValue(PByte(Obj),t);
end;
ftTime:
begin
t := q.FieldByName(TOutroCampo(Atributo).NomeCampo).AsDateTime;
Prop.SetValue(PByte(Obj),t);
end;
end;
end;
end;
end;
end;