Ver Mensaje Individual
  #5  
Antiguo 20-09-2004
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 29
Lepe Va por buen camino
Si no es viable instalar la JVCL puedes usar una funcion de mi autoría, que autocompleta el campo que quieras en un derivado de TcustomEdit. Cambiando un par de cosas, creo que tambien lo podrías usar en un DBedit normal de la VCL.
No chequea si se pega texto en la caja desde el portapapeles.

Código Delphi [-]
  // constantes para el AutoCompleta
  const NO_BUSCAR = 1;
        BUSCAR = 0;
        BUSCAR_SI_CAMBIA = 2; // si no lo encuentra la 1ª vez, no sigue
                             // buscando hasta
                             //  que se borre caracteres anteriores


procedure AutoCompleta(Ctr:TcustomEdit; Key:Word; qry:TDataset;const NombreCampo:string);
const checking :Boolean = False;
      OldText:string='';

var Campo:TField;
begin
  case key of
  vk_DELETE,VK_BACK :
            begin
              Ctr.SelText := '';
              Ctr.Tag:= codigoutil.IfThen(Ctr.Tag=BUSCAR_SI_CAMBIA,BUSCAR, NO_BUSCAR);
            end;
  VK_LEFT,VK_CAPITAL, VK_RIGHT, VK_HOME, VK_END: Ctr.Tag:= NO_BUSCAR;
  else
    Ctr.Tag := codigoutil.IfThen(Ctr.Tag=BUSCAR_SI_CAMBIA,NO_BUSCAR, BUSCAR);
  end;

  if Ctr.Tag = BUSCAR then
  begin
    if checking then Exit;
    checking:= True;
    if (Ctr.SelStart = 0) then
      OldText := Ctr.Text
    else
    OldText:= Copy(Ctr.Text,1,Ctr.SelStart);//+Key;
    if not qry.Active then
      qry.Open;
    if qry.Locate(NombreCampo, OldText  ,[locaseinsensitive, lopartialkey]) then
    begin
      Campo :=qry.FindField(NombreCampo);
      if Campo = nil then
        Exception.Create('proc AutoCompleta: Campo '+QuotedStr(NombreCampo)+' no encontrado')
      else
      begin
        if Key = vk_return then
          Ctr.Text:= Campo.AsString
        else
          Ctr.Text:= OldText + Rightstr(Campo.AsString,Length(Campo.AsString)-Length(OldText));
        Ctr.SelStart:= Length(OldText);
        Ctr.SelLength := Length(Ctr.Text);
  //      SetCaretPos(Length(OldText),1);
        Ctr.Tag:= BUSCAR;
      end;
    end
    else
    begin
      Ctr.Tag:= BUSCAR_SI_CAMBIA;
    end;
    checking:= False;

  end;
end;

Saludos y espero te sirva
Responder Con Cita