Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-12

Can't create calculated field

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Krzysztof

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121230/13e1cf93/attachment.html>

Reply by email

John Landmesser
to Krzysztof

In Delphi 5 i would give you this advice; perhaps update the FieldList?!

  SQLQuery1.FieldDefs.Clear;

.. add your Field ..

SQLQuery1.FieldDefs.Update;
Krzysztof wrote 26 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121230/3ec138c6/attachment.html>

Reply by email

Alejandro Gonzalo
to Krzysztof: I have this code: f := TField.Create(FDataList); f.FieldName := 'calc'; f.FieldKind :=…

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.

Show quoted text 40 lines
________________________________ From: Krzysztof To: Lazarus mailing list 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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130101/5a67c74b/attachment.html>

Reply by email

Mattias Gaertner
to Alejandro Gonzalo
Show quoted text 18 lines
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!

Hint:
You can write
SQLQuery1.OnCalcFields:=|
Then press Shift+Ctrl+C (Code completion) and the OnCalcFields will be created automatically.

Mattias

Reply by email

Krzysztof
to Mattias Gaertner

I know how to create events (from object inspector and in runtime). Everything is connected correctly, events are fired but don't know why this error occur. Calculated fields in Laz SQLDB are different than in Delphi? I'm doing everything what I did in Delphi. My field is created in runtime because I get AV when I try to create field in design time (this is other issue, seems that SQLDB in Code Typhon 3.10 is messed up) -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130102/43bad7ee/attachment.html>

Reply by email