Page 1 of 1
Progress event when fetchning data
Posted: Fri 06 Jan 2012 17:31
by zvasku
Hello,
is it possible to add event for progress when fetchnig data from db server to TUniQuery (etc.).
When fetching large amount of data, App.ProcessMessages to refresh app should be usefull.
Thanks
Zdenek
Posted: Mon 09 Jan 2012 08:46
by AlexP
Hello,
For displaying the process of fetching data from the server you can use the AfterFetch event.
For this you should set the FetchAll option to false and set necessary value in the FetchRows property, for example:
Code: Select all
var
FCounter: integer;
procedure TForm1.UniQuery1AfterFetch(DataSet: TCustomDADataSet);
begin
if UniQuery1.RecordCount > 0 then
ProgressBar1.Position := Round(100*FCounter/UniQuery1.RecordCount);
FCounter := FCounter + UniQuery1.FetchRows;
Application.ProcessMessages;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FCounter:= 0;
UniQuery1.SpecificOptions.Values['FetchAll'] := 'false';
UniQuery1.FetchRows := 25;
UniQuery1.Options.QueryRecCount := true;
UniQuery1.Open;
UniQuery1.Last;
end;
Posted: Mon 09 Jan 2012 10:50
by zvasku
I will test it.
Thanks
Zdenek
Posted: Mon 09 Jan 2012 14:54
by zvasku
Work well, but I need it with TClientDataset-TDatasetProvider where RecourdCount returns 0 (table is not Active). It is ok for this situation.
Is it valid to use FRecordCount in this case?
Posted: Wed 11 Jan 2012 12:23
by AlexP
Hello,
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
Code: Select all
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;
Posted: Thu 12 Jan 2012 09:14
by zvasku
It is another approach. I need to load complete dataset when opening. I only need progressbar or processmessages during one single open:
ShowPorogress;
ClientDataset.Open;
HideProgress;
...
ClientDataset.AddIndex .... etc.
...
Showmodal;
Posted: Thu 12 Jan 2012 11:15
by AlexP
Hello,
ClientDataset does not call any events when retrieving data, that is why you can not visualize the data obtaining process when simply opening ClientDataset (TClientDataset.open)
Posted: Thu 12 Jan 2012 11:42
by zvasku
Yes, but I can use connected TUniQUery to do that. It works good with AfterFetch, also QueryRecCount work as expected.
I'm olny use FRecordCount instead of RecordCount.
Posted: Thu 12 Jan 2012 15:27
by AlexP
Hello,
Please, specify the component, whose property FRecordCount you use.
Posted: Thu 12 Jan 2012 16:02
by zvasku
TUniQuery
Posted: Fri 13 Jan 2012 10:01
by AlexP
Hello,
The FRecordCount field is a protected field of the class, and UniQuery retrieves the value of this field with the help of the RecordCount event. There are special methods implemented for retrieving the number of records depending on the UniQuery. settings. So, if you have even got access to the FRecordCount event, then, most probably, you will retrieve the wrong number of records.