Page 1 of 1
How to recalculate calcfields?
Posted: Mon 25 Jul 2005 13:20
by Ludek
Hi, I need help.
I have a read-only query with calculated fields. In OnCalcField I'm accessing a global variable. This variable gets changed and I need to reflect this change in the grid - to recalculate calcfields in all visible records. How could I do it?
Thanks.
Posted: Tue 26 Jul 2005 09:01
by Ikar
Borland TDataSet doesn't propose suitable variants to solve this task. Do you know how to solve it, for example with BDE or ADO?
Posted: Tue 26 Jul 2005 09:11
by Ludek
With BDE I used following method programmed in subclass of TQuery:
procedure TExtQuery.RecalcAll;
var
i: integer;
begin
for i := 0 to self.BufferCount - 1 do begin
GetCalcFields(Buffers);
DataEvent(deRecordChange, 0); // to update on-screen components
end;
end;
It very often works also with SDAC, but sometimes it generates an assertion in MemLines.pas (source file of SDAC). Am I again douing something wrong?
Posted: Wed 27 Jul 2005 14:04
by Ikar
In this example you are based on using protected methods of TDataSet. Do you know similar way for public methods?
> sometimes it generates an assertion in MemLines.pas
Most probably, it is happens on using local filtering or local sorting.
Posted: Wed 27 Jul 2005 22:21
by Ludek
I don't know a way to do it using public methods. For me, it would be sufficient to do it somehow, even using protected methods - but safe, without exceptions....
Yes, the exceptions appear more often when the filtered property is active, but i've already seen an exception without any filters or local sorting (i don't use local sorting at all - it wasn't supported by BDE

; It seems, that using my method i'm accessing some old, dead buffers, that are not filled by valid data anymore... - am I right? Do I have a way to decide, whether the buffer in the "buffers" array is valid or not?
Posted: Thu 28 Jul 2005 07:07
by Ludek Stauber
I reprogrammed the method this way:
var
i: integer;
begin
for i := 0 to min(BufferCount, RecordCount) - 1 do
GetCalcFields(Buffers);
DataEvent(deRecordChange, 0); // only to update components
end;
it seems to be much more stable now. Is it correct or am I still missing something?
Posted: Thu 28 Jul 2005 07:26
by Ikar
Try to call Resync([]) instead of
var
i: integer;
begin
for i := 0 to min(BufferCount, RecordCount) - 1 do
GetCalcFields(Buffers);
DataEvent(deRecordChange, 0); // only to update components
end;
Posted: Thu 28 Jul 2005 09:45
by Ludek
OK, seems also to work correctly. I'll use it instead of my code, it seems to be even safer. Thanks!
