Tema: dbgrid
Ver Mensaje Individual
  #5  
Antiguo 17-11-2004
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 29
Lepe Va por buen camino
A ver que os parece esta función:
Código Delphi [-]
  {-----------------------------------------------------------------------------
    Procedure: DoLookup
    Author:    Lepe
    Date:      26-abr-2004
    Arguments: qry:TDataset;const NombreCampo:string;
 const Valor:Variant; const DevolverCampo:string
    Result:    Variant
            Mira si existe el campo Nombre
            Si se encuentra devuelve el valor correcto
            Si no se encuentra devuelve Unassigned:
                integer   0
                real        0
                string      empty String
                character same as string (left)
                Boolean      false
  -----------------------------------------------------------------------------}
  function DoLookup(qry:TDataset;const NombreCampo:string;
 const ValorNombreCampo:Variant; const DevolverCampo:string): Variant;
  begin
    Result := Unassigned;
    // si el dataset no está abierto, no hace nada.
    if qry.Active then
    begin
      if (qry.FindField(NombreCampo) = nil) then
        Exception.Create('Parámetro NombreCampo : '+ NombreCampo+
 ' no encontrado en Dataset: ' + qry.Name);
      if qry.FindField(DevolverCampo) = nil then
            Exception.Create('Parámetro DevolverCampo : '+ DevolverCampo +
 ' no encontrado en Dataset: ' + qry.Name);
      if (qry.RecordCount >0) then
      begin
        Result := qry.Lookup(NombreCampo ,ValorNombreCampo,DevolverCampo);
        if (VarType(Result) in [varnull]) then //si no existe el registro
        begin
          Result := Unassigned;
        end;
      end;
    end
  
  end;

Saludos
Responder Con Cita