unit Unit9;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
  FireDAC.Phys, FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, FireDAC.DApt, FireDAC.Comp.Client, Data.DB, FireDAC.Comp.DataSet, Vcl.Grids, AdvObj, BaseGrid, AdvGrid, DBAdvGrid, Vcl.StdCtrls, Vcl.ExtCtrls, FireDAC.Stan.StorageBin;

type
  TForm9 = class(TForm)
    DBAdvGrid1: TDBAdvGrid;
    DataSource1: TDataSource;
    FDMemTable1: TFDMemTable;
    Panel1: TPanel;
    Button2: TButton;
    Label1: TLabel;
    CheckBox1: TCheckBox;
    FDStanStorageBinLink1: TFDStanStorageBinLink;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
   FilterID:Integer;
  public
    { Public declarations }
  end;

var
  Form9: TForm9;

implementation

{$R *.dfm}

procedure TForm9.Button2Click(Sender: TObject);
Var IC:Integer;
begin

 FDMemTable1.DisableControls;

 FDMemTable1.Filtered:=False;


 Case FilterID of
 1:Begin FDMemTable1.Filter:='(GOdina=2025)And(Period=5)And(Vid=1)'; FilterID:=2; End;
 2:Begin FDMemTAble1.Filter:='(GOdina=2025)And(Period=5)And(Vid=2)'; FilterID:=1; End;
 End;


 FDMemTable1.filtered:=true;

 DBAdvGrid1.Columns.Clear;
 With DBAdvGrid1.Columns.Add do width:=15;

 For Ic:=0 to FDMemTable1.FieldCount-1 Do
  DBAdvGrid1.Columns.Add.Field:=FDMemTable1.Fields[Ic];

 FDMemTable1.EnableControls;

 Label1.Caption:='Record count: '+FDMemTable1.RecordCount.ToString;

 Case CheckBox1.Checked of
  True:FDMemTable1.Last;
  False:FDMemTable1.First;
 End;

end;

procedure TForm9.FormCreate(Sender: TObject);
begin
 FilterID:=1;
 FDMemTable1.LoadFromFile('CustTable.fds',sfBinary);
end;

end.
