2
I’m making a system where I need to search the name of the product. Below Edit appears a grid for auto complete, then when I press Enter on the product name, on the grid, you need to appear on the Timage the image, I recorded the path at the time of the product registration.
I’ve been doing research since yesterday and I haven’t found a way.
Follow the image and the code
unit untPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, Buttons, Grids, DBGrids, DB;
type
TfrmBusca = class(TForm)
frmBusca: TImage;
BitBtn1: TBitBtn;
edtBusca: TEdit;
dbgAutoComplete: TDBGrid;
Image1: TImage;
dsBuscaProdutos: TDataSource;
Panel1: TPanel;
edtImagem: TEdit;
procedure BitBtn1Click(Sender: TObject);
procedure edtBuscaChange(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure dbgAutoCompleteKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmBusca: TfrmBusca;
implementation
uses untGerenciamento, untDataModuleCONEXAO, untModuloProdutos;
{$R *.dfm}
procedure TfrmBusca.BitBtn1Click(Sender: TObject);
begin
frmGerenciamento.ShowModal;
end;
procedure TfrmBusca.dbgAutoCompleteKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
edtBusca.Text := dsBuscaProdutos.DataSet.FieldByName('pro_nome').AsString;
dbgAutoComplete.Visible := False;
//Image1.Picture.LoadFromFile(dmCONEXAO.adoCONSULTA_PRODUTOSTODOSpro_imagem);
//edtImagem.Text := dmCONEXAO.adoCONSULTA_PRODUTOSTODOSpro_imagem.AsString;
//if not FileExists(edtBusca.Text) then
// Image1.Picture:= Nil
// Else
end;
end;
procedure TfrmBusca.edtBuscaChange(Sender: TObject);
begin
//puxa os dados e filtra pelo nome da cidade digitado
//dsBuscaProdutos.DataSet.Filter := 'pro_nome like '+QuotedStr('%' +edtBusca.Text+'%');
//ativa o filtro
//dsBuscaProdutos.DataSet.Filtered := false;
//faz teste se estiva não vazio o dsCidades
//if not dsBuscaProdutos.DataSet.IsEmpty then
//ativa a dbgrid
//dbgAutoComplete.Visible := True
//else
//dbgAutoComplete.Visible := False;
//end;
dsBuscaProdutos.DataSet.Filtered := false;
if edtBusca.Text <> '' then
begin
dsBuscaProdutos.DataSet.Filter := 'pro_nome like '+
QuotedStr('%' +edtBusca.Text+'%');
dsBuscaProdutos.DataSet.Filtered := true;
dbgAutoComplete.Visible := True;
end
else
dbgAutoComplete.Visible := False;
end;
procedure TfrmBusca.FormKeyPress(Sender: TObject; var Key: Char);
begin
edtBusca.Text := dsBuscaProdutos.DataSet.FieldByName('pro_nome').AsString;
dbgAutoComplete.Visible := True;
end;
end.
What goes wrong with your code? In a superficial view it seems to work even if it is not the best way, in my opinion.Researched to do this by query using comsndo LIKE ?
– Motta
Error occurring that appears in the image?
– Giovani
just doesn’t pull the image!
– anderson seibert