Try this:
In the interface part of the form unit insert this prototype into the Private
declarations:
private
{ Private declarations }
Procedure OnCalcFields(DataSet: TDataSet); // insert this
Early in the implementation part insert the event procedure:
Procedure TForm1.OnCalcFields(DataSet: TDataSet);
begin
SQLQuery1.FieldByName('calc').AsBoolean := true;
end;
Then after creating your "f" field:
f.DataSet := SQLQuery1.FieldDefs.Dataset;
SQLQuery1.OnCalcFields:=OnCalcFields; // insert this line
Dealing with events without using the Object Inspector can be tricky!
A. G.
>________________________________
> From: Krzysztof <[email protected]>
>To: Lazarus mailing list <[email protected]>
>Sent: Sunday, December 30, 2012 6:26 AM
>Subject: [Lazarus] Can't create calculated field
>
>
>Hi,
>
>
>I have this code:
>
>
> f := TField.Create(FDataList);
> f.FieldName := 'calc';
> f.FieldKind := fkCalculated;
> f.SetFieldType(ftBoolean);
> f.DataSet := SQLQuery1.FieldDefs.Dataset;
>
>
>
>
>procedure TForm1.OnCalc(DataSet: TDataSet);
>begin
> SQLQuery1.FieldByName('calc').AsBoolean := true;
>end;
>
>
>But I get error "Invalid type conversion to Boolean in field calc"
>
>
>Regards
>--
>_______________________________________________
>Lazarus mailing list
>[email protected]
>http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
> --
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus