DateF.pas
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit DateF;
  2. interface
  3. uses
  4.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  5.   Forms, Dialogs, Dates, StdCtrls;
  6. type
  7.   TDateForm = class(TForm)
  8.     LabelDate: TLabel;
  9.     BtnIncrease: TButton;
  10.     BtnDecrease: TButton;
  11.     BtnAdd10: TButton;
  12.     BtnSubtract10: TButton;
  13.     BtnLeap: TButton;
  14.     BtnToday: TButton;
  15.     EditYear: TEdit;
  16.     EditMonth: TEdit;
  17.     EditDay: TEdit;
  18.     Label1: TLabel;
  19.     Label2: TLabel;
  20.     Label3: TLabel;
  21.     BtnRead: TButton;
  22.     BtnWrite: TButton;
  23.     procedure BtnIncreaseClick(Sender: TObject);
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure BtnDecreaseClick(Sender: TObject);
  26.     procedure BtnAdd10Click(Sender: TObject);
  27.     procedure BtnSubtract10Click(Sender: TObject);
  28.     procedure FormDestroy(Sender: TObject);
  29.     procedure BtnLeapClick(Sender: TObject);
  30.     procedure BtnTodayClick(Sender: TObject);
  31.     procedure BtnReadClick(Sender: TObject);
  32.     procedure BtnWriteClick(Sender: TObject);
  33.   private
  34.     TheDay: TNewDate;
  35.   public
  36.     procedure DateChange(Sender: TObject);
  37.   end;
  38. var
  39.   DateForm: TDateForm;
  40. implementation
  41. {$R *.DFM}
  42. procedure TDateForm.DateChange;
  43. begin
  44.   LabelDate.Caption := TheDay.Text;
  45. end;
  46. procedure TDateForm.FormCreate(Sender: TObject);
  47. begin
  48.   TheDay := TNewDate.Create (1998, 12, 25);
  49.   LabelDate.Caption := TheDay.GetText;
  50.   // assign the event handler for future changes
  51.   TheDay.OnChange := DateChange;
  52. end;
  53. procedure TDateForm.BtnIncreaseClick(Sender: TObject);
  54. begin
  55.   TheDay.Increase;
  56. end;
  57. procedure TDateForm.BtnDecreaseClick(Sender: TObject);
  58. begin
  59.   TheDay.Decrease;
  60. end;
  61. procedure TDateForm.BtnAdd10Click(Sender: TObject);
  62. begin
  63.   TheDay.Increase (10);
  64. end;
  65. procedure TDateForm.BtnSubtract10Click(Sender: TObject);
  66. begin
  67.   TheDay.Decrease (10);
  68. end;
  69. procedure TDateForm.FormDestroy(Sender: TObject);
  70. begin
  71.   TheDay.Free;
  72. end;
  73. procedure TDateForm.BtnLeapClick(Sender: TObject);
  74. begin
  75.   if TheDay.LeapYear then
  76.     ShowMessage ('Leap year')
  77.   else
  78.     ShowMessage ('NON Leap year');
  79. end;
  80. procedure TDateForm.BtnTodayClick(Sender: TObject);
  81. begin
  82.   TheDay.SetValue (Date);
  83. end;
  84. procedure TDateForm.BtnReadClick(Sender: TObject);
  85. begin
  86.   EditYear.Text := IntToStr (TheDay.Year);
  87.   EditMonth.Text := IntToStr (TheDay.Month);
  88.   EditDay.Text := IntToStr (TheDay.Day);
  89. end;
  90. procedure TDateForm.BtnWriteClick(Sender: TObject);
  91. begin
  92.   // might cause problems
  93.   {TheDay.Year := StrToInt (EditYear.Text);
  94.   TheDay.Month := StrToInt (EditMonth.Text);
  95.   TheDay.Day := StrToInt (EditDay.Text);}
  96.   // better solution
  97.   TheDay.SetValue (StrToInt (EditYear.Text),
  98.     StrToInt (EditMonth.Text), StrToInt (EditDay.Text));
  99. end;
  100. end.