Ver Mensaje Individual
  #7  
Antiguo 14-06-2010
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.331
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Cita:
Empezado por AzidRain Ver Mensaje
...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
  // recorrido
  for i := 0 to (Self.ComponentCount - 1) do begin
    // componente
    comp := Self.Components[i];
    // Tiene la propiedad
    b := ExistProp(comp, 'DataField');
    if (b) then begin
      // Obtener el valor
      vprop := GetPropAsString(comp, 'DataField');
      // Tiene la prop. rellena?
      if (vprop <> '') then begin
        // posee la propiedad
        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
  // Busca la propiedad y deviuelve la estructura nil
  PropInfo := GetPropInfo(Instance, PropName);
  Result := not (PropInfo = nil);
end;

{:Recupera valor a una propiedad a través de su nombre (via RTTI).}
function GetPropAsString(AObj: TObject; const PropName:String):String;
const
  EBLOCK = 'SetPropAsString';
var
  PInfo: PPropInfo;
  LObject: TObject;
Begin

  Result := '';

  // Existe la propiedad
  if not ExistProp(AObj, PropName) then begin
    Exit;
  end;

  // Intentamos acceder (con un puntero) a la info. de la propiedad
  PInfo := GetPropInfo(AObj.ClassInfo, PropName);

  // Se ha encontrado la propiedad con éste nombre; Chequear el tipo...
  if (PInfo^.Proptype^.Kind = tkString) or
     (PInfo^.Proptype^.Kind = tkLString) or
     (PInfo^.Proptype^.Kind = tkWString) then begin
    // Obtener el resulatado
    Result := GetStrProp(AObj, PInfo);
  end
  else if (PInfo^.Proptype^.Kind = tkInteger) then begin
    // recuperar el valor...
    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);
    // Nada...
    if (LObject <> nil) then begin
      // Es un componente?
      if (LObject is TComponent) then begin
        Result := TComponent(LObject).Name;
        LObject.Free;
      end;
    end;
  end
  else begin
    Result := '';
  end;

end;
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita