Fórum Consulta usando Edit e um DBGrid que serve para varias tabelas #453048
24/08/2013
0
tentei assim..
No edit tem a pesquisa..este sria o codigo
if Edit1.Text <> '' then
begin
TipoPesc := Campo + ' Like' + Quotedstr(Edit1.Text + '%');
PescSQL('Select * from '+Tabela+' where ');
end;
O campo e a Tabela são duas váriáveis do tipo string para que eu possa passar os valores externamente;.
O codigo para receber os parametros é este.
Cursor:=crSQLWait;
FPesquisacGlobal := TFPesquisacGlobal.Create(Self);
try
FPesquisacGlobal.ShowModal;
Cursor := crDefault;
Campo := 'DESCRICAO';
Tabela := 'CONTA_MOVIMENTO';
FPesquisacGlobal.Dts_PescGlobal.DataSet := Dts_PescContaMovimento.DataSet;
finally
FreeAndNil(FPesquisacGlobal);
end;
no caso o campo que é a varialvel global que foi declarada é reponsável pelo qual parte da tabea será feita a busca
no caso do Tabela..recebe o nome da tabela.
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
procedure PescSQL(txt: string);
{ Public declarations }
end;
var
FPesquisacGlobal: TFPesquisacGlobal;
TipoPesc, Campo, Tabela: string;
implementation
uses
DBClient, FCadCx;
{$R *.dfm}
procedure TFPesquisacGlobal.Edit1Change(Sender: TObject);
begin
if Edit1.Text <> '' then
begin
TipoPesc := Campo + ' Like' + Quotedstr(Edit1.Text + '%');
PescSQL('Select * from '+Tabela+' where ');
end;
end;
procedure TFPesquisacGlobal.Edit1Enter(Sender: TObject);
begin
end;
procedure TFPesquisacGlobal.PescSQL(txt: string);
begin
with TClientDataSet(Dts_PescGlobal.DataSet) do
begin
Close;
CommandText:=txt+TipoPesc;
Open;
end;
end;
end.
e este é o codigo completo do sistema de busca..não dá erro más não funciona..vlw
Gilmar Moraes
Curtir tópico
+ 0Posts
24/08/2013
Gilmar Moraes
Gostei + 0
24/08/2013
Gilmar Moraes
Pura desatenção minha..coisa boba mesmo a ordem estava errado..agora ficou assim.
Cursor:=crSQLWait;
FPesquisacGlobal := TFPesquisacGlobal.Create(Self);
try
Campo := 'DESCRICAO';
Tabela := 'CONTA_MOVIMENTO';
FPesquisacGlobal.Dts_PescGlobal.DataSet := Dts_PescContaMovimento.DataSet;
FPesquisacGlobal.ShowModal;
Cursor := crDefault;
finally
FreeAndNil(FPesquisacGlobal);
end;
end;
agora é só questão de estética..teria uma forma de o grid mostar apenas um determinado campo ? tipo o Campo DESCRIÇÂO.
Gostei + 0
24/08/2013
Gilmar Moraes
Cursor:=crSQLWait;
FPesquisacGlobal := TFPesquisacGlobal.Create(Self);
try
Campo := 'DESCRICAO';
Tabela := 'CONTA_MOVIMENTO';
FPesquisacGlobal.Dts_PescGlobal.DataSet := Dts_PescContaMovimento.DataSet;
FPesquisacGlobal.DBGrid4.Columns[0].FieldName := 'DESCRICAO';
FPesquisacGlobal.DBGrid4.Columns[0].Width := 500;
FPesquisacGlobal.ShowModal;
Cursor := crDefault;
finally
FreeAndNil(FPesquisacGlobal);
end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)