Rev 10 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
unit mainunit;{$mode objfpc}{$H+}interfaceusesClasses, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,LCLType, StdCtrls, ExtCtrls, ComCtrls, EditBtn, Buttons, unit1, unit2;type{ TMainForm }TMainForm = class(TForm)StartButton: TBitBtn;CurrentTimeLabel: TLabel;AdvancedLabel: TLabel;AdvancedTimeLabel: TLabel;Label1: TLabel;FoundationLabel: TLabel;FoundationTimeLabel: TLabel;IntermediateLabel: TLabel;IntermediateTimeLabel: TLabel;MainMenu: TMainMenu;FileMenu: TMenuItem;FileExit: TMenuItem;HelpMenu: TMenuItem;HelpAbout: TMenuItem;CurrentTimePanel: TPanel;FoundationPanel: TPanel;IntermediatePanel: TPanel;AdvancedPanel: TPanel;FileExams: TMenuItem;FileSeperator1: TMenuItem;StatusBar: TStatusBar;Timer1: TTimer;procedure FileExamsClick(Sender: TObject);procedure FileExitClick(Sender: TObject);procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);procedure FormCreate(Sender: TObject);procedure FormResize(Sender: TObject);procedure FormShow(Sender: TObject);procedure HelpAboutClick(Sender: TObject);procedure StartButtonClick(Sender: TObject);procedure Timer1Timer(Sender: TObject);private{ private declarations }ClockRunning: Boolean;FoundationDuration, FoundationHalfTime: TDateTime;IntermediateDuration, IntermediateHalfTime: TDateTime;AdvancedDuration, AdvancedHalfTime: TDateTime;Sec, TenMins, ZeroHour: TDateTime;FoundationCaption, IntermediateCaption, AdvancedCaption: String;public{ public declarations }end;varMainForm: TMainForm;implementation{$R *.lfm}{ TMainForm }procedure TMainForm.FileExitClick(Sender: TObject);beginClose;end;procedure TMainForm.FileExamsClick(Sender: TObject);beginif Form2.ShowModal = ID_OK thenbeginFoundationPanel.Enabled := Form2.FoundationCheckBox.Checked;FoundationLabel.Visible := Form2.FoundationCheckBox.Checked;FoundationTimeLabel.Visible := Form2.FoundationCheckBox.Checked;IntermediatePanel.Enabled := Form2.IntermediateCheckBox.Checked;IntermediateLabel.Visible := Form2.IntermediateCheckBox.Checked;IntermediateTimeLabel.Visible := Form2.IntermediateCheckBox.Checked;AdvancedPanel.Enabled := Form2.AdvancedCheckBox.Checked;AdvancedLabel.Visible := Form2.AdvancedCheckBox.Checked;AdvancedTimeLabel.Visible := Form2.AdvancedCheckBox.Checked;end;end;procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);beginCanClose := Application.MessageBox('Confirm application exit?','Confirm Exit', MB_ICONQUESTION+MB_YESNO) = IDYES;end;procedure TMainForm.FormCreate(Sender: TObject);begin// Initalise variablesClockRunning := False;FoundationDuration := StrToTime('00:55:00');FoundationHalfTime := StrToTime('00:27:30');IntermediateDuration := StrToTime('01:25:00');IntermediateHalfTime := StrToTime('00:42:30');AdvancedDuration := StrToTime('02:00:00');AdvancedHalfTime := StrToTime('01:00:00');Sec := StrToTime('00:00:01');TenMins := StrToTime('00:10:00');ZeroHour := StrToTime('00:00:00');end;procedure TMainForm.FormResize(Sender: TObject);varh: Integer;begin// set panel heights to fit screenh := (Height - 2 * StatusBar.Height) div 4;CurrentTimePanel.Height := h;FoundationPanel.Height := h;IntermediatePanel.Height := h;AdvancedPanel.Height := h;Label1.Caption := 'Time Now:';FoundationLabel.Caption := FoundationCaption;IntermediateLabel.Caption := IntermediateCaption;AdvancedLabel.Caption := AdvancedCaption;Application.ProcessMessages;end;procedure TMainForm.FormShow(Sender: TObject);varh: Integer;begin// set panel heights to fit screenh := (Height - 2 * StatusBar.Height) div 4;CurrentTimePanel.Height := h;FoundationPanel.Height := h;IntermediatePanel.Height := h;AdvancedPanel.Height := h;CurrentTimeLabel.Caption := TimeToStr(Time);StatusBar.Panels[0].Text := DateToStr(Date);FoundationCaption := 'Foundation:';FoundationCaption := FoundationCaption + sLineBreak + 'Duration: ' +TimeToStr(FoundationDuration);FoundationCaption := FoundationCaption + sLineBreak + 'Half Time: ' +TimeToStr(FoundationHalfTime);FoundationLabel.Caption := FoundationCaption;FoundationTimeLabel.Caption := TimeToStr(FoundationDuration);IntermediateCaption := 'Intermediate:';IntermediateCaption := IntermediateCaption + sLineBreak + 'Duration: ' +TimeToStr(IntermediateDuration);IntermediateCaption := IntermediateCaption + sLineBreak + 'Half Time: ' +TimeToStr(IntermediateHalfTime);IntermediateLabel.Caption := IntermediateCaption;IntermediateTimeLabel.Caption := TimeToStr(IntermediateDuration);AdvancedCaption := 'Advanced:';AdvancedCaption := AdvancedCaption + sLineBreak + 'Duration: ' +TimeToStr(AdvancedDuration);AdvancedCaption := AdvancedCaption + sLineBreak + 'Half Time: ' +TimeToStr(AdvancedHalfTime);AdvancedLabel.Caption := AdvancedCaption;AdvancedTimeLabel.Caption := TimeToStr(AdvancedDuration);end;procedure TMainForm.HelpAboutClick(Sender: TObject);beginForm1.ShowModal;end;procedure TMainForm.StartButtonClick(Sender: TObject);varstart: TDateTime;beginstart := Time;FoundationCaption := 'Foundation:';FoundationCaption := FoundationCaption + sLineBreak + 'Duration: ' +TimeToStr(FoundationDuration);FoundationCaption := FoundationCaption + sLineBreak + 'Half Time: ' +TimeToStr(start + FoundationHalfTime);FoundationCaption := FoundationCaption + sLineBreak + 'End Time: ' +TimeToStr(start + FoundationDuration);FoundationLabel.Caption := FoundationCaption;IntermediateCaption := 'Intermediate:';IntermediateCaption := IntermediateCaption + sLineBreak + 'Duration: ' +TimeToStr(IntermediateDuration);IntermediateCaption := IntermediateCaption + sLineBreak + 'Half Time: ' +TimeToStr(start + IntermediateHalfTime);IntermediateCaption := IntermediateCaption + sLineBreak + 'End Time: ' +TimeToStr(start + IntermediateDuration);IntermediateLabel.Caption := IntermediateCaption;AdvancedCaption := 'Advanced:';AdvancedCaption := AdvancedCaption + sLineBreak + 'Duration: ' +TimeToStr(AdvancedDuration);AdvancedCaption := AdvancedCaption + sLineBreak + 'Half Time: ' +TimeToStr(start + AdvancedHalfTime);AdvancedCaption := AdvancedCaption + sLineBreak + 'End Time: '+TimeToStr(start + AdvancedDuration);AdvancedLabel.Caption := AdvancedCaption;// start the clockClockRunning := True;StartButton.Enabled := False;end;procedure TMainForm.Timer1Timer(Sender: TObject);beginCurrentTimeLabel.Caption := TimeToStr(Time);StatusBar.Panels[0].Text := DateToStr(Date);if ClockRunning thenbegin// update the displayif FoundationPanel.Enabled thenbeginFoundationDuration := FoundationDuration - Sec;if FoundationDuration = ZeroHour thenbeginFoundationTimeLabel.Color := clRed;FoundationPanel.Enabled := False;endelsebeginif FoundationDuration <= TenMins thenFoundationTimeLabel.Color := clFuchsiaelsebeginif FoundationDuration <= FoundationHalfTime thenFoundationTimeLabel.Color := clYellow;end;end;FoundationTimeLabel.Caption := TimeToStr(FoundationDuration);end;if IntermediatePanel.Enabled thenbeginIntermediateDuration := IntermediateDuration - Sec;if IntermediateDuration = ZeroHour thenbeginIntermediateTimeLabel.Color := clRed;IntermediatePanel.Enabled := False;endelsebeginif IntermediateDuration <= TenMins thenIntermediateTimeLabel.Color := clFuchsiaelsebeginif IntermediateDuration <= IntermediateHalfTime thenIntermediateTimeLabel.Color := clYellow;end;end;IntermediateTimeLabel.Caption := TimeToStr(IntermediateDuration);end;if AdvancedPanel.Enabled thenbeginAdvancedDuration := AdvancedDuration -Sec;if AdvancedDuration = ZeroHour thenbeginAdvancedTimeLabel.Color := clRed;AdvancedPanel.Enabled := False;endelsebeginif AdvancedDuration <= TenMins thenAdvancedTimeLabel.Color := clFuchsiaelsebeginif AdvancedDuration <= AdvancedHalfTime thenAdvancedTimeLabel.Color := clYellow;end;end;AdvancedTimeLabel.Caption := TimeToStr(AdvancedDuration);end;end;Label1.Caption := 'Time Now:';FoundationLabel.Caption := FoundationCaption;IntermediateLabel.Caption := IntermediateCaption;AdvancedLabel.Caption := AdvancedCaption;Application.ProcessMessages;end;end.