简体   繁体   中英

RecordCount with UniDAC Dataset component

I'm using the TUniQuery component from UniDAC. 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. 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.

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

also from 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

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;

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