unit grid;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Query1: TQuery;
    DataSource1: TDataSource;
    Query1CODIGO: TIntegerField;
    Query1NOME: TStringField;
    Query1IDENTIDADE: TFloatField;
    Query1CPF: TStringField;
    Query1ENDERECO: TStringField;
    Query1BAIRRO: TStringField;
    Query1CIDADE: TStringField;
    Query1UF: TStringField;
    Query1CEP: TStringField;
    Query1OBS: TStringField;
    Query1FONEUM: TStringField;
    Query1FONEDOIS: TStringField;
    Query1EMAIL: TStringField;
    Query1REFUM: TStringField;
    Query1FONEREFUM: TStringField;
    Query1REFDOIS: TStringField;
    Query1FONEREFDOIS: TStringField;
    DBGrid1: TDBGrid;
    Button1: TButton;
    Query2: TQuery;
    DataSource2: TDataSource;
    DBGrid2: TDBGrid;
    Query1EscolhaCidade: TStringField;
	function ConsultaNormal(ConsultaNormal:TQuery;Expressao:string):Boolean;
    procedure Button1Click(Sender: TObject);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function Tform1.ConsultaNormal(ConsultaNormal:TQuery;Expressao:string):Boolean;
var resultado:boolean;
begin
  resultado := true;
  consultaNormal.active := false; consultaNormal.sql.clear; consultaNormal.sql.add(expressao);
  consultaNormal.active := true;
  if consultaNormal.recordcount = 0 then
     resultado := false;
  result := resultado;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
//   DBGRID1.Color := clinfobk;
//   dbgrid1.Columns.Clear;
//	  showmessage(inttostr(dbgrid1.Columns.Count));
end;

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
   i:integer;
begin
   For i := 0 to DbGrid1.Columns.Count -1 do
      DBgrid1.Columns.Items[i].Color := ClWindow;
   DBGrid1.Columns.Items[Column.ID].Color := clInfoBk;
   ConsultaNormal(Query1,'select * from cliente order by '+column.FieldName);
end;

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
	if key = 13 then
   	key := 9;
end;

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
	Key := upcase(key);
end;

end.
