home *** CD-ROM | disk | FTP | other *** search
/ EDUCORP 8 / Educorp2Compilation.sit / educorp2 / Programming (2300, 7000) / 2306 Programming v.4 / TimeUnit / TimeTest Unit < prev   
Encoding:
Text File  |  1987-04-11  |  2.2 KB  |  90 lines

  1. Unit TimeBomb(897);
  2.  
  3. {$U-}                          
  4.  
  5. INTERFACE
  6.  
  7. Uses MemTypes,Quickdraw,OSIntf,ToolIntf,PackIntf;
  8.  
  9.     Function TimeTest(numSecs: longInt) : Boolean;
  10.     
  11. IMPLEMENTATION
  12.  
  13. VAR
  14.  
  15.     Error       :       Integer;
  16.     StartDate   :       LongInt;
  17.     CurrDate    :       LongInt;
  18.     FinalTicks  :       LongInt;
  19.     
  20.  
  21. Function TimeTest;
  22.  
  23. Const
  24.  
  25.     ResType     =       'TDAT';
  26.     SecsToMin   =       86400;
  27.     
  28. Type
  29.     TimeHandle  =       ^TimePtr;
  30.     TimePtr     =       ^TimeStruct;
  31.     TimeStruct  =       Record
  32.                              Old        :       LongInt;
  33.                              New        :       LongInt;
  34.                              Other      :       LongInt;
  35.                              OldString  :       Str255;
  36.                              NewString  :       Str255;
  37.                         End;
  38. Var
  39.     TimeCheck   :   TimeHandle;
  40.     BlankHandle :   Handle;
  41.     String1     :   Str255;
  42.     String2     :   Str255;
  43.     
  44.  
  45. Begin
  46.     GetDateTime(CurrDate);
  47.     TimeCheck := TimeHandle(GetResource(ResType,0));
  48.     If TimeCheck = Nil then
  49.     
  50.        { --------------------------------
  51.          We cannot find a Resource so we
  52.          Create one.  This is only used
  53.          Once. 
  54.          -------------------------------- }
  55.          
  56.         Begin           
  57.             TimeCheck := TimeHandle(NewHandle(SizeOf(TimeStruct)));
  58.             TimeCheck^^.Old := CurrDate;
  59.             IUDateString(CurrDate,LongDate,String1);
  60.             IUTimeString(CurrDate,TRUE,String2);
  61.             String1 := String1 + String2 + '                          ';
  62.             TimeCheck^^.OldString := String1;
  63.             AddResource(Handle(TimeCheck),ResType,0,'');
  64.             WriteResource(Handle(TimeCheck));
  65.             Error := ResError;
  66.         End;
  67.     
  68.     { Now Check to see if time has been exceeded }
  69.     
  70.     StartDate := TimeCheck^^.Old;
  71.     FinalTicks := NumSecs + StartDate;
  72.     
  73.     If CurrDate > FinalTicks then
  74.         Begin
  75.             TimeTest := True;
  76.         end
  77.         Else
  78.         Begin
  79.             TimeTest := False;
  80.         End;
  81.         
  82.         {If we have an Error trying to access the Resource file
  83.           i.e. Write Protected, then we have a time exceed = true }
  84.           
  85.         If ResError <> 0 then TimeTest := True;
  86. End;
  87.  
  88.  
  89. Begin
  90. End.