When uniQuery is opened, why DataSource.onDataChange trigger 2 times?

473 views Asked by At

I've a question about unidac's uniQuery:

when uniQuery open, if a DataSource component is linked, the DataSource.onDataChange will trigger 2 times, and ADOQuery trigger just 1 time, why?

Environment:

  1. uniDAC:6.4, 7;
  2. delphi: 7, xe 10.1 berlin
1

There are 1 answers

0
Dreamer64 On

I faced the same problem many times, I found that it is a default loading behavior not just in the Uni-component, all similar database components will trigger .onDataChange twice or more when loading, the only way to go over it is by using workarounds to ignore the 1st trigger.

You can find also a similar problem here

If triggering twice is annoying you, try my workaround for it:

var c: integer;  // must be global and reset to 0 when u close your query  

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
    begin
      if c = 2 then
        begin
          // do your actions
        end
      else
        begin
          inc(c);
        end;
    end;

It will eliminate all none necessary triggers,
hope that helps.