Page 1 of 1

dataset editing/inserting & filter

Posted: Wed 01 Jun 2016 12:54
by Ludek
Hi,
I'm having following problem: i have a filtered tmsquery (filter = 'a = 5'), do an append, set a to 6 and post. the record immediately after post disappers. Even in afterpost is an other record active. This makes big trouble, if the code in afterpost event somehow analyzes the currently posted data (as it analyzes an other record).

Is there some nice way to "correct" this? Or, at least, to disallow such post, if the new record won't meet the filter criteria? I tried anything like subclassing tmsquery and writing code like

Code: Select all

procedure TMyMSQuery.InternalPost;
begin
    if (data as TMemData).OmitRecord((data as TMemData).GetCurrentItem) then
      raise Exception.Create('Saved record would be filtered out. Save aborted.');
  inherited;
end;
byt currentitem is nil dataset in dsinsert state... also OmitRecord(activebuffer) did not work... Some other way?
Thanks, Ludek.

Re: dataset editing/inserting & filter

Posted: Tue 07 Jun 2016 07:31
by AlexP
Hello,

This is correct behavior, since AfterPost occurs after the record is "written" into the DataSet, and all the conditions, that are applied to the DataSet, are applied to the record as well. If you want to analyze the inserted data, you should use the BeforePost event.