Search code examples
sqldelphifiremonkeypascalrad-studio

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


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;

Solution

  • 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);