Jump to content
bazzer747

Filter on InternalCalc field

Recommended Posts

Hi,

I see this but it doesn't help me in that it isn't working for me - I've listed the code I'm using above and there is nothing complicated about it. So if you can filter on an internally calculated field then why does it not work?

 

Should work and actually working are two different things, as I've experienced in Delphi many times over the years. 

 

I'll set up a small project with nothing other than the bare minimum and try again with a more simple filter and see what happens. If that still doesn't work for me I'm going back to a simple Select statement to filter the records (which I know works as that's what I did before trying the internal calc way.

Share this post


Link to post

I've tried with calculated field to use in OnFilterRecord and it worked, the grid displayed only the filtered records. 

Share this post


Link to post

Hi

 

I setup my small project and tried again, with no success. I tried with a normal Filter and also with OnFilterRecord, neither worked with an InternalCalc field. The documentation suggests it should work, but it doesn't (for me anyway).

 

If you did get it working can you show some code showing the internalcalc field and the filter code. Maybe it's just a small mistake somewhere that stops it working.

 

PS I have it all working fine now using a SELECT SQL statement, so IO'm just now interested in the final answer.

Share this post


Link to post

My code is simple

type
  TForm1 = class(TForm)
    FDConnection1: TFDConnection;
    FDQuery1: TFDQuery;
    FDQuery1field1: TStringField;
    FDQuery1calcfield: TStringField;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FDQuery1CalcFields(DataSet: TDataSet);
    procedure FDQuery1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  FDQuery1.Filtered:=true;
end;

procedure TForm1.FDQuery1CalcFields(DataSet: TDataSet);
begin
 dataset['calcfield']:=varToStr(dataset['field1'])+' data';
end;

procedure TForm1.FDQuery1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
  Accept:=copy(varToStr(dataset['calcfield']),1,1)='1';
end;

 

filtered.png

unfiltered.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×