User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 391,980 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,132 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:

OnCalcField modifying its own DataSet - Error

Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 67
Reputation: Micheus is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
Micheus's Avatar
Micheus Micheus is offline Offline
Junior Poster in Training

Re: OnCalcField modifying its own DataSet - Error

  #4  
May 7th, 2008
Originally Posted by MoZo1 View Post
So every time I try to move the active record from inside the OnCalcField event I get a lot of some veird EOleException invalid argument error, even when I don't even read or write any data.
Does you have looked in the help file and search for OnCalcFields event?

MoZo1, this event occurs in many circumstances and many times. See this small portion:
OnCalcFields is called frequently, so the code it contains should be brief.
When the AutoCalcFields property is True, OnCalcFields is triggered when:

• A dataset is opened.
• A dataset is put into dsEdit state.
• Focus moves from one visual control to another, or from one column to another is a data-aware grid control and modifications were made to the record.
• A record is retrieved from a database.


So, from the moment that dataset is opened until all data is showed in the DBGrid, your application will notice that OnCalcEvent was triggered a lote of times.
You can have an idea from this by putting one TMemo (Memo1) into your form and adding this code to your OnCalcFields event:
  1. procedure TForm1.calc(DataSet: TDataSet);
  2. begin
  3. Memo1.Lines.Add('OnCalcFields passed...');
  4. end;
You never must change any data field from dataset owned by calculated field (except from the calculated fields), as well dataset position at this event (it will generate recursive calls).

If You need to make some thing when a DBGrid selection is changed (current record has its position changed), You must use the OnDataChange evento from TDataDouce componente connected to desired dataset.

Bye
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)

Brazil - Blumenau
Reply With Quote  
All times are GMT -4. The time now is 9:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC