Cita:
Empezado por AzidRain
...no se me ocurre una idea "elegante" de borrar todos los cambios hechos a los campos (recordemos que el registro aún no ha sido posteado ya que el Post lo hace el formulario principal) que no sea la de recorrer los databindings de los controles de estos formularios y limpiar manualmente sus valores. Un simple "for cada control en el formulario limpia los datos del campo que tenga ligado".
|
Ese form se puede hacer utilizando RTTI. Posees funciones para saber si un componente posee una propiedad (DataField) y también para conocer el valor que tiene. Con eso debería bastar para poder realizar ese
FOR, que necesitas.
Con un ADOTable sería así:
Código Delphi
[-]procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
b:Boolean;
vprop:string;
comp:TComponent;
begin
for i := 0 to (Self.ComponentCount - 1) do begin
comp := Self.Components[i];
b := ExistProp(comp, 'DataField');
if (b) then begin
vprop := GetPropAsString(comp, 'DataField');
if (vprop <> '') then begin
ADOTable1.FieldByName(vprop).Clear;
end;
end;
end;
end;
Te adjunto las 2 funciones que aparecen;
ExistProp y
GetPropAsString; Sólo te queda añadir al USES la unit
TypInfo.
Código Delphi
[-]function ExistProp(Instance: TObject; const PropName: string):Boolean;
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(Instance, PropName);
Result := not (PropInfo = nil);
end;
function GetPropAsString(AObj: TObject; const PropName:String):String;
const
EBLOCK = 'SetPropAsString';
var
PInfo: PPropInfo;
LObject: TObject;
Begin
Result := '';
if not ExistProp(AObj, PropName) then begin
Exit;
end;
PInfo := GetPropInfo(AObj.ClassInfo, PropName);
if (PInfo^.Proptype^.Kind = tkString) or
(PInfo^.Proptype^.Kind = tkLString) or
(PInfo^.Proptype^.Kind = tkWString) then begin
Result := GetStrProp(AObj, PInfo);
end
else if (PInfo^.Proptype^.Kind = tkInteger) then begin
Result := IntToStr(GetInt64Prop(AObj, PInfo));
end
else if (PInfo^.Proptype^.Kind = tkEnumeration) then begin
Result := GetEnumProp(AObj, PInfo);
end
else if (PInfo^.PropType^.Kind = tkClass) then begin
LObject := GetObjectProp(AObj, PInfo);
if (LObject <> nil) then begin
if (LObject is TComponent) then begin
Result := TComponent(LObject).Name;
LObject.Free;
end;
end;
end
else begin
Result := '';
end;
end;