Marco Web Center |
|
Chapter 02 - Project Dates1 |
Project Structure |
Dates1.dpr |
program Dates1; uses Forms, Dates1Form in 'Dates1Form.pas' {Form1}; {$R *.RES} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. |
Dates1Form.pas |
unit Dates1Form; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TDate = class Month, Day, Year: Integer; procedure SetValue (m, d, y: Integer); function LeapYear: Boolean; end; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; EditYear: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TDate.SetValue (m, d, y: Integer); begin Month := m; Day := d; Year := y; end; function TDate.LeapYear: Boolean; begin // call IsLeapYear in SysUtils.pas Result := IsLeapYear (Year); end; procedure TForm1.Button1Click(Sender: TObject); var ADay: TDate; begin // create an object ADay := TDate.Create; // use the object ADay.SetValue (1, 1, StrToInt (EditYear.Text)); if ADay.LeapYear then ShowMessage ('Leap year: ' + IntToStr (ADay.Year)); // destroy the object ADay.Free; end; end. |
Dates1Form.dfm |
object Form1: TForm1 Left = 192 Top = 107 Width = 291 Height = 186 Caption = 'Dates1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 72 Top = 88 Width = 25 Height = 13 Caption = 'Year:' end object Button1: TButton Left = 72 Top = 48 Width = 130 Height = 25 Caption = 'Leap Year?' TabOrder = 0 OnClick = Button1Click end object EditYear: TEdit Left = 104 Top = 84 Width = 98 Height = 21 Color = clWindow TabOrder = 1 Text = '2000' end end |