Ir para conteúdo
Fórum Script Brasil

Bettega

Membros
  • Total de itens

    28
  • Registro em

  • Última visita

Tudo que Bettega postou

  1. Bettega

    Dúvida com Array

    Em princípio, para diminuir as linhas de programação, mas também para entender como utilizar arrays. Obrigado.
  2. Estou tentando fazer um Form de Pesquisa, utilizando arrays. Fiz da seguinte forma, mas não consigo definir os dados do array. Sempre dá erro na declaração do array. procedure TF_Pesquisa.FormShow(Sender: TObject); // Para definir os dados do DBGrid. var aCampos : array [ 1..2, 1..3 ] of String ; // Campo 1 = Nome do campo da Tabela a ser pesquisado // Campo 2 = Título no DBGrid // Campo 3 = Largura do campo do DBGrid i : Integer ; begin if DONDE.Caption = 'Cad_Clientes' then aCampos := [ [ 'COD_CLIENTE', 'Cód.', '70' ], [ 'NOME', 'Cliente', '420' ] ] ; if DONDE.Caption = 'Cad_Fornecedores' then aCampos := [ [ 'COD_FORNECEDOR', 'Cód.', '70' ], [ 'RAZAO', 'Fornecedor', '420' ] ] ; for i := 1 to 2 do begin DBGrid1.Columns.Add ; DBGrid1.Columns[i-1].FieldName := aCampos [ i, 1 ] ; // Coluna 0 DBGrid1.Columns[i-1].Title.Caption := aCampos [ i, 2 ] ; DBGrid1.Columns[i-1].Width := StrToInt ( aCampos [ i, 3 ] ) ; end; end ; procedure TF_Pesquisa.Ed_PesqExit(Sender: TObject); // Ed_Pesq = tEdit - palavra a ser localizada begin Query1.Close ; Query1.SQL.Clear ; if DONDE.Caption = 'Cad_Clientes' then begin Query1.SQL.Add ( 'Select * from Cad_Clientes' ) ; Query1.SQL.Add ( 'Where NOME like "%' + Ed_Pesq.Text + '%" ' ) ; Query1.SQL.Add ( 'Order by NOME' ); end; if DONDE.Caption = 'Cad_Fornecedores' then begin Query1.SQL.Add ( 'Select * from Cad_Fornecedores' ) ; Query1.SQL.Add ( 'Where RAZAO like "%' + Ed_Pesq.Text + '%" ) ' ) ; Query1.SQL.Add ( 'Order by RAZAO' ); end; Query1.Open ; end ; A pesquisa está funcionando perfeitamente. O problema está na definição do array. Obrigado, Bettega.
  3. Estou tentando fazer um Form de Pesquisa, utilizando arrays. Fiz da seguinte forma, mas não consigo definir os dados do array. Sempre dá erro na declaração do array. procedure TF_Pesquisa.FormShow(Sender: TObject); // Para definir os dados do DBGrid. var aCampos : array [ 1..2, 1..3 ] of String ; // Campo 1 = Nome do campo da Tabela a ser pesquisado // Campo 2 = Título no DBGrid // Campo 3 = Largura do campo do DBGrid begin if DONDE.Caption = 'Cad_Clientes' then begin aCampos := [ [ 'COD_CLIE', 'Cód.', '70' ], [ 'NOME', 'Cliente', '420' ] ] ; for i := 1 to 2 do begin DBGrid1.Columns.Add ; DBGrid1.Columns[i-1].FieldName := aCampos [ i, 1 ] ; DBGrid1.Columns[i-1].Title.Caption := aCampos [ i, 2 ] ; DBGrid1.Columns[i-1].Width := StrToInt ( aCampos [ i, 3 ] ) ; end; end ; if DONDE.Caption = 'Cad_Fornecedores' then begin aCampos := [ [ 'COD_FORN', 'Cód.', '70' ], [ 'RAZAO', 'Fornecedor', '420' ] ] ; for i := 1 to 2 do begin DBGrid1.Columns.Add ; DBGrid1.Columns[i-1].FieldName := aCampos [ i, 1 ] ; DBGrid1.Columns[i-1].Title.Caption := aCampos [ i, 2 ] ; DBGrid1.Columns[i-1].Width := StrToInt ( aCampos [ i, 3 ] ) ; end; end ; end ; procedure TF_Pesquisa.Ed_PesqExit(Sender: TObject); // Ed_Pesq = tEdit - palavra a ser localizada begin Query1.Close ; Query1.SQL.Clear ; if DONDE.Caption = 'Cad_Clientes' then begin Query1.SQL.Add ( 'Select * from Cad_Clientes' ) ; Query1.SQL.Add ( 'Where ( NOME like "%' + Ed_Pesq.Text + '%" ) or ( RAZAO like "%' + Ed_Pesq.Text + '%" ) ' ) ; Query1.SQL.Add ( 'Order by NOME' ); end; if DONDE.Caption = 'Cad_Fornecedores' then begin Query1.SQL.Add ( 'Select * from Cad_Fornecedores' ) ; Query1.SQL.Add ( 'Where ( NOME like "%' + Ed_Pesq.Text + '%" ) or ( RAZAO like "%' + Ed_Pesq.Text + '%" ) ' ) ; Query1.SQL.Add ( 'Order by NOME' ); end; Query1.Open ; end ; A pesquisa está funcionando perfeitamente. O problema está na definição do array. Obrigado, Bettega.
×
×
  • Criar Novo...