RecordCount with UniDAC Dataset component

2.8k views Asked by At

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?

2

There are 2 answers

0
user3777264 On

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;
0
Boris Matkov On

Try setting the QueryRecCount option to True

UniQuery1.Options.QueryRecCount := True;