browse data without scrolling

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

browse data without scrolling

Post by Ludek » Thu 04 Oct 2007 14:42

Hi, I'm already long time fighting with an problem and haven't found a good solution yet, perhaps have you an idea?
simple scenario:
user is editing data in grid (appending new rows, deleting records, etc.) and the system on-line updates statistics about all inserted data - sums, averages, ... many things. the dataset is in cached updates mode.
now the problem:
the user appended a row and the dataset is in dsInsert mode. he changed a value and the system needs to update its statistics immediately - look at all inserted data in order first -> last and do some computations. How could this be done?
1. solution like:

d.getbookmark;
d.Post;
d.First;
while not d.EOF do
d.next;
end;
d.gotobookmark;

is crazy, because:
a. post ist perhaps not possible - all required fields are not filled yet.
b. the worst thing for me - the record loses its dsinsert state and gets into dsBrowse (or dsEdit)...

2. solution like:
storing the data duplicately in an array or list don't like at all because of the need of really good working synchronization, that i am really aware of... I hate duplicating data. :evil:

could someone give me a tip? something like an alternative read-only pointer to the same dataset?

Thanks very much.
Ludek.

last remark - there are not many records in the dataset, typically 10 or 20, sometimes 100.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 08 Oct 2007 07:10

I can suggest you a solution when you alter you statistic regarding the data that a user currently enters using the OnChange event of fields in the dataset. In the BeforeEdit event of the dataset you need to remember field values of the current record.
Code in the OnChange event of fields will look like this:

Code: Select all

var
  stat_val1, old_field1_value: integer;
  stat_val2, old_field2_value: integer;
  ...

procedure TForm1.MyQuery1Field1Change(Sender: TField);
begin
  if Sender.DataSet.State = dsInsert then
    stat_val1 := stat_val1 + Sender.AsInteger
  else
    if Sender.DataSet.State = dsEdit then
      stat_val1 := stat_val1 + (Sender.AsInteger - old_field1_value)
...
end;
This code will vary regarding your application.

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Mon 08 Oct 2007 12:30

Well, my statistics are nearly impossible to implement so incrementally - because incrementally computed values sometimes slighty differ from sstatical sum and that could be very dangerous. that is all about the float number rounding problems, as you know:

a+0,01-0,01 is often unequal a.

The dbgrid component can access nonactive rows without scrolling, is really nothing similar accessible for application developers?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 09 Oct 2007 07:01

This is the behaviour of the TDataSet class which is inherited TMSQuery/TMSTable from, therefore this behaviour cannot be changed.

After posting a record, you can update your statistic using actual data.

Post Reply