DTTry (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

 This example demonstrates the use of some routines in the DateUtils unit.

Code

procedure TMainForm.btActionClick(Sender: TObject);
var
  DateTime: TDateTime;
begin
  if rgActions.ItemIndex = 0 then
    TryEncodeDateDay(StrToInt(edYear.Text),StrToInt(edDayYear.Text),DateTime);
  if rgActions.ItemIndex = 1 then
    TryEncodeDateMonthWeek(StrToInt(edYear.Text),StrToInt(edMonth.Text),
      StrToInt(edWeekMonth.Text),StrToInt(edDayWeek.Text),DateTime);
  if rgActions.ItemIndex = 2 then
    TryEncodeDateWeek(StrToInt(edYear.Text),StrToInt(edWeekYear.Text),
      DateTime,StrToInt(edDayWeek.Text));
  if rgActions.ItemIndex = 3 then
    TryEncodeDayOfWeekInMonth(StrToInt(edYear.Text),StrToInt(edMonth.Text),
      StrToInt(edDayWeekMonth.Text),StrToInt(edDayWeek.Text),DateTime);
  if rgActions.ItemIndex = 4 then
    TryRecodeDateTime(DateTime,StrToInt(edYear2.Text),StrToInt(edMonth2.Text),
      StrToInt(edDay.Text),StrToInt(edHour.Text),StrToInt(edMinute.Text),
      StrToInt(edSecond.Text),StrToInt(edMilliSecond.Text),DateTime);
  edDateTime.Text := DateTimeToStr(DateTime);
end;

Uses