Skip to main content

Example: Using the foBetween Filter Operator

This example shows you how to create a filter condition with the BETWEEN operator. The BETWEEN operator requires two values identifying an inclusive range. These two values must be combined into an array of variants and this is performed by the VarBetweenArrayCreate function implemented in the cxVariants unit.

To add a filter condition, use the AddItem method of the data controller’s Filter object. The new filter condition is applied to the cxGrid1DBTableView1PurchaseDate column of the cxGrid1DBTableView1 view.

var
  d1, d2: TDateTime;
//...
  d1 := EncodeDate(2000, 01, 01);
  d2 := EncodeDate(2000, 01, 03);
  cxGrid1DBTableView1.DataController.Filter.AddItem(nil, 
    cxGrid1DBTableView1PurchaseDate,  foBetween, 
    VarBetweenArrayCreate(d1, d2), 
    DateToStr(d1) + ';' + DateToStr(d2));