Edward Diener writes:
Quote
Will the field information be automatically filled with the results
of the query when I set Active to true, or do I manually have to fill
in any information here for each field I create ?
Everything happens automatically just as with dynamic fields or static
field objects created at design time.
Quote
>end;
>
>{ This is how you can add additional calculated fields }
>Field := TStringField.Create(Table1);
>Field.FieldName := 'Total';
>Field.Calculated := True;
>Field.DataSet := Table1;
OK, this looks good. Shouldn't a field type also be set here ?
The field type is set by the class of field object you create. This
example creates a TStringField so the type is string. Create
TIntegerField, TFloatField etc. depending on your needs.
Quote
>
>{ Now we can see our fields. }
>Table1.Active := True;
How does OnCalcFields now work ? Is it called once for each record of
the query when the dataset is open ? Or is it called once when the
query is executed and it is up to my code to cycle through each
record in order to update the calculated field(s)?
The following is from the on-line help.
OnCalcFields is triggered when:
A dataset is opened.
A dataset is put into dsEdit state.
A record is retrieved from a database.
When the AutoCalcFields property is true, OnCalcFields is also
triggered when:
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.
Note: When the AutoCalcFields property is true, an OnCalcFields event
handler should not modify the dataset (or a linked dataset if it is
part of a master-detail relationship), because such modifications
retrigger the OnCalcField event, leading to infinite recursion.
If an application permits users to change data, OnCalcFields is
frequently triggered. To reduce the frequency with which OnCalcFields
occurs, set AutoCalcFields to false.
Warning: When the dataset is the master table of a master-detail
relationship, OnCalcFields occurs before detail sets have been
synchronized with the master table.
--
Bill Todd (TeamB)