EncodeTime (C++)

From Appmethod Code Examples
Jump to: navigation, search

Description

This example uses three edit controls, a label, and a button on a form. When you click the button, the day, month, and year specified in the edit controls is stored in a TDateTime object. Then the TDateTime object is converted to a String that is displayed in the label.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TDateTime dt;
  try
  {
    dt = EncodeTime((Word)StrToInt(Edit1->Text), (Word)StrToInt(Edit2->Text), (Word)StrToInt(Edit3->Text), (Word)StrToInt(Edit4->Text));
    Label1->Caption = TimeToStr(dt);
  }
  catch(...)
  {
    ShowMessage("Invalid hour, minute, second, or millisecond.");
  }
}

Uses