简体   繁体   English

带有 UniDAC 数据集组件的 RecordCount

[英]RecordCount with UniDAC Dataset component

I'm using the TUniQuery component from UniDAC.我正在使用 UniDAC 的 TUniQuery 组件。 I'd like to show how many records I have, so我想显示我有多少记录,所以

I've put the following code to show in a Status Bar:我已将以下代码显示在状态栏中:

procedure TForm1.unyQuery1AfterFetch(DataSet: TCustomDADataSet);
begin
    StatusBar1.Panels[1].Text := 'Número de registros: ' + inttostr(unyQuery1.RecordCount);
end;

UnyQuery1.RecordCount always returns zero. UnyQuery1.RecordCount 始终返回零。 But if I run this code from a button click event it works.但是,如果我从按钮单击事件运行此代码,则它可以工作。

What I'm doing wrong?我做错了什么?

Use the AfterOpen event of the Query and not AfterFetch. 使用查询的AfterOpen事件而不是AfterFetch。

procedure TForm1.UniQuery1AfterOpen(DataSet: TDataSet);
begin
StatusBar1.Panels[1].Text:= 'Records: ' + inttostr(uniQuery1.RecordCount);
end;

also from devart: 同样来自devart:

For the mapping of the data-getting process in ClientDataSet you should set the ClientDataSet.PacketRecord property equal to UniQuery.FetchRows and use the ClientDataSet.GetData event for the mapping of the data-getting process 对于ClientDataSet中的数据获取过程的映射,应将ClientDataSet.PacketRecord属性设置为UniQuery.FetchRows并使用ClientDataSet.GetData事件进行数据获取过程的映射

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientDataSet1.PacketRecords := 25;
ClientDataSet1.Open;
  while not ClientDataSet1.eof do
    ClientDataSet1.next;
end;

procedure TForm1.DataSetProvider1GetData(Sender: TObject;
  DataSet: TCustomClientDataSet);
begin
if ClientDataSet1.Active then ShowMessage(IntToStr(ClientDataSet1.RecordCount));
end;

尝试将 QueryRecCount 选项设置为 True

UniQuery1.Options.QueryRecCount := True;

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

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