How to recalculate calcfields?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ludek

How to recalculate calcfields?

Post by Ludek » Mon 25 Jul 2005 13:20

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.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 26 Jul 2005 09:01

Borland TDataSet doesn't propose suitable variants to solve this task. Do you know how to solve it, for example with BDE or ADO?

Ludek

Post by Ludek » Tue 26 Jul 2005 09:11

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?

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 27 Jul 2005 14:04

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.

Ludek

Post by Ludek » Wed 27 Jul 2005 22:21

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?

Ludek Stauber

Post by Ludek Stauber » Thu 28 Jul 2005 07:07

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?

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 28 Jul 2005 07:26

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;

Ludek

Post by Ludek » Thu 28 Jul 2005 09:45

OK, seems also to work correctly. I'll use it instead of my code, it seems to be even safer. Thanks! :)

Post Reply