Recent

Author Topic: BufDataSet speed  (Read 2641 times)

HappyLarry

  • Full Member
  • ***
  • Posts: 144
BufDataSet speed
« on: August 23, 2016, 10:28:06 am »
In order to perform calculations on the fields of a Bufdataset I need to access each record in the dataset. I 'scroll' through the dataset with
Code: Pascal  [Select]
  1.       Self.First;
  2.       While not Self.EOF do
  3.       begin
  4.         Self.next;
  5.       end;
It seems quite slow (e.g. 2 secs for 10000 records or 14 secs for 30000 records) - perhaps this is about right?

Am I doing this in the best way or is there a better way?
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7931
Re: BufDataSet speed
« Reply #1 on: August 23, 2016, 10:45:50 am »
Is the set wired to some grid? Best is to do such things on datasets that are not bound to GUI controls.

HappyLarry

  • Full Member
  • ***
  • Posts: 144
Re: BufDataSet speed
« Reply #2 on: August 23, 2016, 12:00:04 pm »
Thanks marcov - it makes a huge difference - it now loads in millisecs which is good.

However, once I have 'wired' the dataset to datasource1 with
   Datasource1.dataset := T;
in order to show iit, I can't see how to 'unwire' it in order to scroll and then wire it again to show the results.

Neither
    Datasource1.dataset.cancel
nor
    Datasource1.enabled:=false;
nor
   Datasourse1.destroy
'unwires it'.

This may be obvious, but how can I temporarily unwire Datasource1 from my dataset?
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

ttomas

  • Full Member
  • ***
  • Posts: 187
Re: BufDataSet speed
« Reply #3 on: August 23, 2016, 12:58:31 pm »
Code: Pascal  [Select]
  1.    Self.DisableControls;
  2.    try
  3.       Self.First;
  4.       While not Self.EOF do
  5.       begin
  6.         Self.next;
  7.       end;
  8.    finally
  9.       Self.EnableControls;
  10.    end;
  11.