Executing OnCalcFields without refreshing non-calced-fields

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
BigAl66
Posts: 11
Joined: Thu 10 Feb 2011 18:28
Location: Germany

Executing OnCalcFields without refreshing non-calced-fields

Post by BigAl66 » Sun 24 Jul 2011 09:21

Hi,

I try to recalc all fields of a TMSQuery without refreshing the data from the database server. The background is, that I have a field, that is dependet from the current time. Example:

DB-Field 1: TStart: TDateTime;
DB-Field 2: TStop: TDateTime;
Calc-Field: Duration: TDateTime;

In the OnCalc-Event the Duration will be calced as follows ():

Code: Select all

if not TStop.IsNull then
  Duration.AsDateTime := TStop.AsDateTime - TStart.AsDateTime
else
  Duration.AsDateTime := Now - TStart.AsDateTime;
Calling a Refresh of the query will update all fields but will allways execute also a complete refresh to the SQL-Server... My data is displayed in a TDBCtrlGrid. Therefore I need a dataaware component to display the field...

Any idea?

Alex

AndreyZ

Post by AndreyZ » Mon 25 Jul 2011 12:06

Hello,

The TMSQuery component inherits calculated fields' functionality from the TDataSet component. There is the GetCalcFields protected virtual method in TDataSet that refreshes calculated fields. You can create your own query class inherited from TMSQuery, override this method, and make it public. After this you will be able to refresh calculated fields without refreshing data from the server by calling the GetCalcFields method.

BigAl66
Posts: 11
Joined: Thu 10 Feb 2011 18:28
Location: Germany

Post by BigAl66 » Mon 25 Jul 2011 16:59

Hi Andrey,

thank you very much for you reponse. I will try your solution.

Best Regards

Alex

BigAl66
Posts: 11
Joined: Thu 10 Feb 2011 18:28
Location: Germany

Post by BigAl66 » Tue 26 Jul 2011 06:02

Hi Andrey,

again. I tried it and it works :D - but also just calling Resync([]) do work? The calculated fields are updated and no access to the database is monitored. Is there any reason why not use just Resync?

Regards

Alex

AndreyZ

Post by AndreyZ » Tue 26 Jul 2011 10:45

You can use both variants.

Post Reply