Muchas gracias por todas sus respuestas anteriores, me han dado mucha luz por donde debo ir, y la solución que hasta va bien es usar RTTI.
El objetivo es crear funciones clasicas como ObjectInsert(Obj: TObject):String, de iguakl manera un ObjectUpdate; ObjectDelete y GetObject:TObject;
Para el caso de ObjectInsert, lo ha desarrolado un amigo y hasta funciona bien, pero lo estoy volviendo hacer para poder incorporar la opción de maestro/detalle y tambien que guarde en una tabla llamada BITACORA para poder controlar cualquier movimiento de los usuarios.
Código Delphi
[-]
function TDm.ObjectInsert(Obj: TObject): String;
var
MiProcedimiento: TFDStoredProc;
MiError:String;
Detalle : widestring;
ListaProp: TStringList;
ListaParam: TStringList;
ListaMetaInfo : TStringList;
NombreProc: string;
NombreProp: string;
NombreParam: string;
TipoProp : string;
TipoDato : string;
TipoIO : string;
AnchoCampo: string;
contexto : TRTTIContext;
propiedad : TRTTIProperty;
valor : TValue;
I, J : word;
function BuscaLong(B: string): string;
var
Encontrado : boolean;
Nombre: string;
Tipo : string;
Ancho:string;
J: Integer;
begin
Encontrado := False;
for J := 0 to Pred(ListaMetaInfo.Count) do
begin
if B = Copy(ListaMetaInfo[J], 1, Length(B)) then
begin Encontrado := True;
Break;
end;
end;
if Encontrado then
TLibreria.ParseMetaInfo(ListaMetaInfo[J], Nombre, Tipo, Ancho)
else
Ancho := '100';
result := Ancho
end;
function BuscaProp(B: string): integer;
var
Encontrado : boolean;
Nombre: string;
Tipo : string;
Ancho:string;
J: Integer;
begin
Encontrado := False;
for J:= 0 to Pred(ListaProp.Count) do
begin
if Copy(B, 2, Length(B)) = Copy(ListaProp[J], 2, Length(B)-1) then
begin
Encontrado := True;
Break;
end;
end;
if Encontrado then
result := J
else
result := -1;
end;
begin
MiError := '';
ListaProp := TStringList.Create;
ListaParam := TStringList.Create;
if not Assigned(Obj) then
exit;
try
MiProcedimiento := TFDStoredProc.Create(nil);
MiProcedimiento.Connection := DM.EmpresaConnection;
ListaProp := TLibreria.DaListaPropConTipo(Obj);
try
with MiProcedimiento do
begin
Close;
Params.Clear;
NombreProc := Copy(Obj.ClassName, 2, Length(Obj.ClassName)-1) + 'Insertar';
StoredProcName := NombreProc;
FetchOptions.Items := MiProcedimiento.FetchOptions.Items - [fiMeta];
ListaParam := DM.DaListaParam(Dm.EmpresaConnection.Params.Database , NombreProc);
ListaMetaInfo := TLibreria.DaListaMetaInfo(Copy(Obj.ClassName, 2, Length(Obj.ClassName)-1));
contexto := TRTTIContext.Create;
for I := 0 to Pred(ListaParam.Count) do
begin
TLibreria.ParseParam(ListaParam[i], NombreParam, TipoDato, TipoIO); AnchoCampo := BuscaLong( Copy(NombreParam, 2, length(NombreParam)-1)); if (TipoDato = 'varchar') And (StrToInt(AnchoCampo) = 8000) then begin
Params.CreateParam( ftWideString, NombreParam, TLibreria.StrToParamType(TipoIO)); for J := 0 to Pred(ListaProp.Count) do begin
TLibreria.ParseProp(ListaProp[J], NombreProp, TipoProp); if TipoProp = 'TObjectList' then begin Detalle := Dm.GetDetalleText(TObjectList(contexto.GetType(Obj.ClassType).GetProperty(NombreProp).GetValue(Obj). AsObject));
Params.ParamByName( NombreParam).Value := Detalle;
end;
end;
end
else begin Params.CreateParam( TLIbreria.StrToFieldType(TipoDato), NombreParam, TLibreria.StrToParamType(TipoIO)); if (Uppercase(NombreParam) = '@ERROR') then begin Params.ParamByName( NombreParam).Value := '';
end
else begin J := BuscaProp(NombreParam); TLibreria.ParseProp(ListaProp[J], NombreProp, TipoProp); propiedad := contexto.GetType(Obj.ClassType).GetProperty(NombreProp); valor := propiedad.GetValue(Obj).ToString; Params.ParamByName( NombreParam).Value := valor.AsString;
end;
end;
end;
contexto.Free;
if ParamCount > 0 then
begin
ExecProc;
MiError := Params.ParamByName('@Error').AsString;
end;
end;
finally
MiProcedimiento.Free;
end;
finally
result := MiError;
ListaProp.Free;
ListaParam.Free;
end;
end;
hay varias funciones que las estoy depurando, cuando las tenga lista se las paso, me parece super interesante estas funciones básicas para cualquier tabla.
les reitero mi agradecimiento por el apoyo brindado.
un fuerte abrazo.