0

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?

Arioch 'The
  • 15,799
  • 35
  • 62
Daniel Grillo
  • 2,368
  • 4
  • 37
  • 62
  • Have you tried to search for "UniDAC progress fetch" ? – TLama Dec 27 '13 at 22:34
  • 1
    Onhttp://docwiki.embarcadero.com/Libraries/XE5/en/Data.DB.TDataSet.RecordCount gives some generic advice on recordCount. Count could depend on where you are in the TUniDac Dataset. If it returns 0 then you have not fetched any perhaps. Look at what @TLama said – DavidG Dec 28 '13 at 02:06
  • What are the settings you have for FetchAll and QueryRecCount? Are you in blocking or non-blocking mode? – Sam M Dec 28 '13 at 03:50
  • Wrong is using record-count for non-ISAM (not dbf or paradox) data sources – Arioch 'The Dec 28 '13 at 18:25
  • What is the actual database? – user3927897 Jan 31 '15 at 15:49

2 Answers2

0

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;
user3777264
  • 72
  • 1
  • 9
0

Try setting the QueryRecCount option to True

UniQuery1.Options.QueryRecCount := True;