unit Form.MainForm;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TForm1 =
class( TForm )
EnsureCurrentDateTimer: TTimer;
CurrentDateLabel: TLabel;
procedure FormShow( Sender: TObject );
procedure EnsureCurrentDateTimerTimer( Sender: TObject );
procedure FormHide( Sender: TObject );
private
FCurrentDate: TDate;
procedure SetCurrentDate(
const Value: TDate );
procedure DoRefreshFormData( );
procedure DoEnsureCurrentDate( );
protected
property CurrentDate: TDate
read FCurrentDate
write SetCurrentDate;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
System.DateUtils;
procedure TForm1.DoEnsureCurrentDate;
begin
CurrentDate := Date;
end;
procedure TForm1.DoRefreshFormData;
begin
CurrentDateLabel.Caption := DateToStr( CurrentDate );
end;
procedure TForm1.EnsureCurrentDateTimerTimer( Sender: TObject );
begin
DoEnsureCurrentDate( );
end;
procedure TForm1.FormHide( Sender: TObject );
begin
EnsureCurrentDateTimer.Enabled := False;
end;
procedure TForm1.FormShow( Sender: TObject );
begin
DoEnsureCurrentDate( );
EnsureCurrentDateTimer.Enabled := True;
end;
procedure TForm1.SetCurrentDate(
const Value: TDate );
var
LValue: TDate;
begin
LValue := DateOf( Value );
if FCurrentDate <> LValue
then
begin
FCurrentDate := LValue;
DoRefreshFormData( );
end;
end;
end.