InChange := True;
if (IsNumericString(txtYear.Text)) and (txtYear.Text <> '') then begin
IdDateTimeStamp1.SetYear(StrToInt(txtYear.Text));
Calc;
end;
InChange := False;
end;
procedure TForm1.txtSecondChange(Sender: TObject);
begin
if InChange then exit;
txtSecond.Text := Copy(txtSecond.Text, 1, 5);
InChange := True;
if (IsNumericString(txtSecond.Text)) and (txtSecond.Text <> '') then begin
IdDateTimeStamp1.SetSecond(StrToInt(txtSecond.Text));
Calc;
end;
InChange := False;
end;
procedure TForm1.txtSecondExit(Sender: TObject);
begin
if InChange then exit;
InChange := True;
if IsNumericString(txtSecond.Text) then begin
udSecond.Position := StrToInt(txtSecond.Text);
end else begin
txtSecond.Text := IntToStr(udSecond.Position);
end;
Calc;
InChange := False;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
if FirstTime then begin
FirstTime := False;
IdDateTimeStamp1.SetFromTDateTime(Now);
Calc;
end;
end;
procedure TForm1.cmdNowClick(Sender: TObject);
begin
IdDateTimeStamp1.SetFromTDateTime(Now);
Calc;
end;
procedure TForm1.cmdResetClick(Sender: TObject);
begin
IdDateTimeStamp1.SetYear(1);
IdDateTimeStamp1.SetDay(1);
IdDateTimeStamp1.SetSecond(1);
IdDateTimeStamp1.SetMillisecond(1);
Calc;
end;
procedure TForm1.udYearClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddYears(1);
end else if Button = btPrev then begin {Down}
IdDateTimeStamp1.SubtractYears(1);
end;
Calc;
InChange := False;
end;
procedure TForm1.udDayClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddDays(1);
end else if Button = btPrev then begin {Down}
IdDateTimeStamp1.SubtractDays(1);
end;
Calc;
InChange := False;
end;
procedure TForm1.udSecondClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin
IdDateTimeStamp1.AddSeconds(1); {Up}
end else if Button = btPrev then begin
IdDateTimeStamp1.SubtractSeconds(1); {Down}
end;
Calc;
InChange := False;
end;
procedure TForm1.udWeekClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddWeeks(1);
end else if Button = btPrev then begin {Down}
IdDateTimeStamp1.SubtractWeeks(1);
end;
Calc;
InChange := False;
end;
procedure TForm1.udMonthClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddMonths(1);
end else if Button = btPrev then begin {Down}
IdDateTimeStamp1.SubtractMonths(1);
end;
Calc;
InChange := False;
end;
procedure TForm1.udMinuteOfDayClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddMinutes(1);
end else if Button = btPrev then begin {Down}
IdDateTimeStamp1.SubtractMinutes(1);
end;
Calc;
InChange := False;
end;
procedure TForm1.udHourOf12DayClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddHours(1);
end else if Button = btPrev then begin {Down}
IdDateTimeStamp1.SubtractHours(1);
end;
Calc;
InChange := False;
end;
procedure TForm1.udMillisecondClick(Sender: TObject; Button: TUDBtnType);
begin
if InChange then exit;
InChange := True;
if Button = btNext then begin {Up}
IdDateTimeStamp1.AddMilliseconds(1);
end else begin {Down}
IdDateTimeStamp1.SubtractMilliseconds(1);
end;
Calc;
InChange := False;
end;
function IsNumericString(const AString : String) : Boolean;
var
i, j : Integer;
begin
i := 1;
j := length(AString);
result := True;
while i <= j do begin
if not IsNumeric(AString[i]) then begin
result := False;
break;
end;
Inc(i);
end;
end;
procedure TForm1.Calc;
begin
InChange := True;
lblYear.Caption := IntToStr(IdDateTimeStamp1.Year);
txtYear.Text := lblYear.Caption;
// Hack due to limitation of TUpDown
udYear.Position := IdDateTimeStamp1.Year div 5;
if IdDateTimeStamp1.IsLeapYear then begin
lblIsLeapYear.Caption := 'Yes';
end else begin
lblIsLeapYear.Caption := 'No';
end;
lblSeconds.Caption := IntToStr(IdDateTimeStamp1.Second);
txtSecond.Text := lblSeconds.Caption;
// Hack due to limitations of TUpDown control
udSecond.Position := (IdDateTimeStamp1.Second div 3) + 1;