Home > OS >  In Delphi, how can I multiply a sql field and a value?
In Delphi, how can I multiply a sql field and a value?

Time:05-27

I want to change the text of label1 by multiplying query field with value of spinBox1. But it doesn't work. ** Fields[3] saved as Integer in my table **

label1.Text := MSQuery1.Fields[3].AsInteger * spinBox1.Value;

or

label1.Text := MSQuery1.Fields[3].AsInteger * spinBox1.Text.ToInteger;

CodePudding user response:

Assuming:

  1. Your application is FMX based then Label1.Text is okay, else you need Label1.Caption
  2. SpinBox comes from FMX library, the Value type is Double, not an Integer

The code is:

Label1.Text := (MSQuery1.Fields[3].AsInteger * SpinBox1.Value).ToString;
// Or using older versions of Delphi
Label1.Text := FloatToStr(MSQuery1.Fields[3].AsInteger * SpinBox1.Value);

CodePudding user response:

You need Label1.caption instead of Label1.Text and it is a string, so you need IntToStr function to convert integer (if it is integer) to string.

  • Related