Ir para conteúdo
Fórum Script Brasil
  • 0

Como Consultar Um String No Dbgrid? - RESOLVIDO


Tenente Leite

Pergunta

Estou desenvolvendo um pequeno projeto no Delphi 6 e não estou conseguindo fazer um formulário de pesquisa.

Tenho que pesquisar por Nome, Alcunha e Identidade,

Só consegui fazer funcionar por Identidade, e mesmo assim a linha com o registro não está recebendo foco, ou seja, ficando colorida,

e a pesquisa por alcunha ou nome, não está funcionando. Não consegui desenvolver código algum, dei uma pesquisada na net mas o código travou.

CÓDIGO

=====================================================
unit UPesquisa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, Buttons, Mask, DB, ExtCtrls;

type
  TFrmPesquisa = class(TForm)
    DBGrid1: TDBGrid;
    BitBtn1: TBitBtn;
    EditChave: TMaskEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    RaGr: TRadioGroup;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure EditChaveChange(Sender: TObject);
    procedure RaGrClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmPesquisa: TFrmPesquisa;

implementation

uses UDM, Ufuncprd, UPesquisaSql;

{$R *.dfm}

procedure TFrmPesquisa.BitBtn1Click(Sender: TObject);
begin
prdRetornaValor(inttostr(Dm.TblCadastroRG.Asinteger),false);
EditChave.Text:='';
FrmPesquisa.Close;
end;

procedure TFrmPesquisa.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
DM.TblCadastro.Close;
end;

procedure TFrmPesquisa.FormShow(Sender: TObject);
begin
DM.TblCadastro.Open;
DM.TblCadastro.refresh;
EditChave.EditMask:='';
EditChave.SetFocus;
Editchave.selectall;
end;

procedure TFrmPesquisa.EditChaveChange(Sender: TObject);
begin
  if RaGr.ItemIndex = 2  then
     begin
       if editChave.Text <> '' then
          DM.TblCadastro.findNearest([(editChave.Text)]);
       end
    else
       begin
         DM.TblCadastro.findNearest([editChave.Text]);
       end;
end;

procedure TFrmPesquisa.RaGrClick(Sender: TObject);
begin
if RaGr.ItemIndex = 0 then
        begin
                Label3.Caption := 'O NOME:';
                DM.TblCadastro.IndexFieldNames := 'Nome';
                DM.TblCadastro.FindNearest([EditChave.Text]);
                editChave.SetFocus;
        end
else
   if RaGr.ItemIndex = 1 then
        begin
                Label3.Caption := 'A ALCUNHA:';
                DM.TblCadastro.IndexFieldNames := 'Alcunha';
                DM.TblCadastro.FindNearest([EditChave.Text]);
                editChave.SetFocus;
        end
   else
        begin
                Label3.Caption := 'A IDENTIDADE:';
                DM.TblCadastro.IndexName :='';
                EditChave.Text:=inttostr(Dm.TblCadastroRG.Asinteger);
                editChave.EditMask:='';
                editChave.SetFocus;
        end;
end;


end.
====================================================

Obrigado

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

Visitante
Este tópico está impedido de receber novos posts.


  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...