[Lazarus] Can't create calculated field
Alejandro Gonzalo
parkingspace26 at yahoo.com
Tue Jan 1 20:54:43 CET 2013
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 <dibo20 at wp.pl>
>To: Lazarus mailing list <lazarus at lists.lazarus.freepascal.org>
>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
>Lazarus at lists.lazarus.freepascal.org
>http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130101/5a67c74b/attachment-0002.html>
More information about the Lazarus
mailing list