简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM