Originally Posted by
MoZo1
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:
procedure TForm1.calc(DataSet: TDataSet);
begin
Memo1.Lines.Add('OnCalcFields passed...');
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