#pragma link "Grids"
#include "BCrack.h"
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Busc1.h"
#include "BCrack.h"

//---------------------------------------------------------------------
#pragma link "Grids"
#pragma resource "*.dfm"

TDlgBuscProd *DlgBuscProd;
//---------------------------------------------------------------------
__fastcall TDlgBuscProd::TDlgBuscProd(TComponent* AOwner)
	: TForm(AOwner)
{
  Form1 -> TBuscar->FieldByName("Nombre")->Index = 0;
}
//---------------------------------------------------------------------
void __fastcall TDlgBuscProd::ComboBox1Change(TObject *Sender)
{
  // Make the field we're locating in the leftmost field.
  Form1 -> TBuscar->FieldByName(ComboBox1->Text)->Index = 0;
/*
  // In order to use FindNearest, we have to be indexed based on the field
  // we're doing the find in.  If we're using Locate, it doesn't matter what
  // the current index is, so we will set it to company, which is the default
  // in the Customer form.

  if (ComboBox1->Text == "CustNo")
*/
    Form1 -> TBuscar->IndexName = "";

/*
  else
    DM2->CustLookup->IndexName = "ByCompany";
*/

  Edit1->SetFocus();
  Edit1->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TDlgBuscProd::Edit1Change(TObject *Sender)
{
  AnsiString BuscarEsto;

  BuscarEsto = Edit1->Text;

  { // Some non-indexed field.
    if ( //ComboBox1->Text != "Nombre del Producto"  &&
         BuscarEsto == "" )
        BuscarEsto = "0";

    Set<TLocateOption,0,1> flags;
    flags << loCaseInsensitive << loPartialKey;
    // Possibly apply the filter so we see only records matching this value.
    bool found;
    found = Form1 -> TBuscar->Locate(ComboBox1->Text,
                                    BuscarEsto,
                                    flags);

    if ( found )
    {
      AnsiString BuscarCota;
      BuscarCota = BuscarEsto + "Z";

      Form1 -> TBuscar->FilterOptions = Form1 -> TBuscar->FilterOptions << foCaseInsensitive;

      Form1 -> TBuscar->Filtered = true;
      Form1 -> TBuscar->Filter = "([" + ComboBox1->Text + "] >= '" + BuscarEsto + "') AND [" + ComboBox1->Text + "] < '" + BuscarCota + "'";
    }
    else
      Form1 -> TBuscar->Filtered = false;
  }

  Form1 -> TBuscar->Refresh();

}
//---------------------------------------------------------------------------
void __fastcall TDlgBuscProd::DBGrid1DblClick(TObject *Sender)
{
  ModalResult = mrOk;
}
//---------------------------------------------------------------------------





