unit uFormModelodePesquisa;

interface

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

type
  TfrmModelodePesquisa = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Label2: TLabel;
    edtPesquisa: TdaEdit;
    DBGrid1: TDBGrid;
    Label3: TLabel;
    Image3: TImage;
    Image1: TImage;
    Panel3: TPanel;
    Image2: TImage;
    Label1: TLabel;
    btnNovo: TBitBtn;
    procedure DBGrid1DblClick(Sender: TObject);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edtPesquisaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmModelodePesquisa: TfrmModelodePesquisa;

implementation

{$R *.dfm}

procedure TfrmModelodePesquisa.DBGrid1DblClick(Sender: TObject);
begin
  Self.ModalResult := mrOk;
end;

procedure TfrmModelodePesquisa.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case KEY of
    VK_RETURN: Self.ModalResult := mrOk;
    VK_ESCAPE: edtPesquisa.SetFocus;
  end;
end;

procedure TfrmModelodePesquisa.edtPesquisaKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  case KEY of
    VK_RETURN: Self.ModalResult := mrOk;
    VK_ESCAPE: Self.ModalResult := mrNo;
  end;
end;

procedure TfrmModelodePesquisa.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  bDirecao: Integer;
begin
  bDirecao := -1;
  if not (ActiveControl is TDBGrid) then
  begin
    case Key of
      VK_UP: bDirecao := 1;
      VK_DOWN,VK_RETURN: bDirecao := 0;
    end;

    if (bDirecao <> -1) then
      perform(WM_NEXTDLGCTL, bDirecao, 0) ;
  end;
end;

end.
