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.
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.
browse data without scrolling
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:
This code will vary regarding your application.
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;
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?
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?