unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls,Unit2, Unit3, tijdreken;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Timer1: TTimer;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Button1: TButton;
    Label5: TLabel;
    Label6: TLabel;
    Button2: TButton;
    Image1: TImage;
    Button3: TButton;

    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure UpdateTime (Sender : TObject);
    private
    { Private declarations }
    procedure ErrorConverting;
  public
    { Public declarations }
  end;


var
  Form1: TForm1;

implementation

{$R *.DFM}
var
  duur, dmin : smallint;
  Tijd : TDateTime;
  luur,lmin : smallint;        {Lokale tijd}
  uur,min,sec,msec : smallint; {GMT tijd}
  atuur,atmin : smallint;      {at tijd}
  deuur,demin,desec,demsec : word;
  PAppl : TApplication;


procedure TForm1.FormCreate(Sender: TObject);

var IniFile : TextFile;
     S : string;
begin
  AssignFile (IniFile,'gats_time.ini');
  {$I-}
  Reset(IniFile);
  {$I+}
  If (IOResult=0) then
  begin
    Readln (Inifile,s);
    try
    duur:=StrToInt (s);
    except
      on EConvertError do ErrorConverting;
    end;
    Readln (Inifile,s);
    try
    dmin:=StrToInt (s);
    except
      on EConvertError do ErrorConverting;
    end;
    CloseFile (Inifile);
  end
  else
  begin
    Label1.Caption:='NO INI FILE!!!';
  end;
end;

procedure TForm1.ErrorConverting;
begin
  Label1.Caption:='ERROR!!!';
end;

procedure TForm1.UpdateTime (Sender : TObject);
begin
  Tijd:= Time;
  DecodeTime(Tijd, deuur, demin, desec, demsec);
  luur:= deuur;
  lmin:=demin;
  sec:=desec;

  addtime (luur,lmin,duur,dmin,uur,min);
  attime (uur,min,atuur,atmin);

  if WindowState<>wsMinimized then
  begin
  Label2.Caption:=IntToStr ( atuur )+'at:'+IntToStr(atmin)+':'+IntToStr(sec);
  Label5.Caption:=IntToStr ( luur )+':'+IntToStr(lmin)+':'+IntToStr(sec);
  Label1.Caption:=IntToStr ( uur )+':'+IntToStr(min)+':'+IntToStr(sec);
  end;
  {else}
  begin
    with Owner as Tapplication do
    Title:=IntToStr ( atuur )+'at:'+IntToStr(atmin)+':'+IntToStr(sec);
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var IniFile: TextFile;
    S : String;
begin
  Form2.UpDown1.Position:=duur;
  Form2.Updown2.Position:=dmin;
  if (Form2.ShowModal)=mrOk then
  begin
    duur:=Form2.UpDown1.Position;
    dmin:=Form2.UpDown2.Position;
    AssignFile (IniFile,'gats_time.ini');
    {$I-}
    ReWrite (IniFile);
    {$I+}
    If (IOResult=0) then
    begin
      Writeln (IniFile,IntToStr(duur));
      Writeln (IniFile,IntToStr(dmin));
      CloseFile (IniFile);
    end
    else
    begin
    end;
  end
  else
  begin

  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Caption:='Wereldtijd converter';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Form3.duur:=duur;
  Form3.dmin:=dmin;
  Form3.Edit1.Text:=IntToStr(luur);
  Form3.Edit2.Text:=IntToStr(lmin);
  Form3.Edit4.Text:=IntToStr(atuur);
  Form3.Edit5.Text:=IntToStr(atmin);
  Form3.ShowModal;
end;

end.
