简体   繁体   English

打开uniQuery时,为什么DataSource.onDataChange触发2次?

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

I've a question about unidac's uniQuery : 我对unidac的uniQuery有疑问:

when uniQuery open, if a DataSource component is linked, the DataSource.onDataChange will trigger 2 times, and ADOQuery trigger just 1 time, why? uniQuery打开时,如果链接了DataSource组件,则DataSource.onDataChange将触发2次,而ADOQuery仅触发1次,为什么?

Environment: 环境:

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

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. 我多次遇到相同的问题,我发现这是默认的加载行为,不仅是在Uni组件中,所有类似的数据库组件在加载时都会触发.onDataChange两次或更多次,唯一的解决方法是使用变通办法忽略第一个触发器。

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. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 Delphi 崩溃时数据库控件的数据源消失 - Why do datasource of database-controls dissapear when Delphi crashes delphi唯一性中的UPDATE和DELETE代码 - Code for UPDATE and DELETE in delphi uniquery 为什么在按下Ctrl + A时会触发TEdit.OnChange? - Why does TEdit.OnChange trigger when Ctrl+A is pressed? 为什么用FILE_FLAG_NO_BUFFERING打开文件时写入失败? - Why does writing to a file fail when it's opened with FILE_FLAG_NO_BUFFERING? 处理postgresql表的Uniquery和身份自动增量cloumn的最佳方法 - Best way to handle Uniquery and identity autoincrement cloumn of a postgresql Table Delphi-对话框打开时键盘钩处于活动状态 - Delphi - keyboard hook active when dialog opened 打开Delphi时,Adoconnection会询问用户名和密码 - Adoconnection asks for userid and password when opened Delphi 为什么将鼠标移到TButton上时,FormPaint事件被触发了多次? - Why is the FormPaint event triggered mutilple times when mouse is moved over a TButton OnDataChange内部的代码多次执行 - Code inside OnDataChange executed multiple time 使用带有可变字符串日期值的UniQuery在Delphi中传递MySQL日期范围查询,使我返回NULL - Passing MySQL date range query in Delphi using UniQuery with variable string date values gives me returns NULL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM