SysUtilsFormat (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses several edit boxes and a button on a form. After filling in some input data into the edit boxes, press the Format button to display the resulting formatted string.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  String text = Edit1->Text;
  int signed_integer = StrToInt(Edit2->Text);
  int hexa_integer = StrToInt(Edit3->Text);
  double floating_point = StrToFloat(Edit4->Text);

  /*
    Format the data using the following rules:
    * Only the first 3 characters of text are displayed.
    * Signed_integer is displayed as a signed integer
      with 10 padding zeros.
    * Hexa_integer is displayed in hexadecimal with 8 padding zeros.
    * Floating_point is displayed as a fixed point value,
      using a width of 10 and a precision of 2 digits.
  */

  Edit5->Text = Format("%.3s, %.10d, $%.8x, %10.2f",
  ARRAYOFCONST((text, signed_integer, hexa_integer, floating_point)));
}

Uses