home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / Essentials / SETUP.EXE / %MAINDIR% / EsUtil.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-11-28  |  3.0 KB  |  134 lines

  1. {*********************************************************}
  2. {*                   ESUTIL.PAS 1.05                     *}
  3. {*      Copyright (c) 1997-98 TurboPower Software Co     *}
  4. {*                 All rights reserved.                  *}
  5. {*********************************************************}
  6.  
  7. {$I ES.INC}
  8.  
  9. {$B-} {Complete Boolean Evaluation}
  10. {$I+} {Input/Output-Checking}
  11. {$P+} {Open Parameters}
  12. {$T-} {Typed @ Operator}
  13. {$W-} {Windows Stack Frame}
  14. {$X+} {Extended Syntax}
  15.  
  16. {$IFNDEF Win32}
  17.   {$G+} {286 Instructions}
  18.   {$N+} {Numeric Coprocessor}
  19.   {$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
  20. {$ENDIF}
  21.  
  22. unit EsUtil;
  23.   {-general utility routines}
  24.  
  25. interface
  26.  
  27. uses
  28.   {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  29.   Graphics, SysUtils, SRMgr;
  30.  
  31. function DaysInMonth(Year, Month : Integer) : Integer;
  32.   {-return the number of days in the specified month of a given year}
  33. function DefaultEpoch : Integer;
  34.   {-return the current century}
  35. function GetLeftButton : Byte;
  36. procedure GetRGB(Clr : TColor; var IR, IG, IB : Byte);
  37. function IsLeapYear(Year : Integer) : Boolean;
  38.   {-return True if Year is a leap year}
  39. function Max(I, J : Integer) : Integer;
  40. function Min(I, J : Integer) : Integer;
  41.  
  42. var
  43.   StrRes : TpsStringResource;
  44.  
  45. implementation
  46.  
  47.  
  48. function DaysInMonth(Year, Month : Integer) : Integer;
  49. var
  50.   Cent : Integer;
  51.   Y    : Word;
  52.   M    : Word;
  53.   D    : Word;
  54. begin
  55.   case Month of
  56.     1, 3, 5, 7, 8, 10, 12 :
  57.       Result := 31;
  58.     4, 6, 9, 11 :
  59.       Result := 30;
  60.     2 : begin
  61.           if Year < 100 then begin
  62.             DecodeDate(SysUtils.Date, Y, M, D);
  63.             Cent := (Y div 100) * 100;
  64.             Year := Year + Cent;
  65.           end;
  66.           Result := 28+Ord(IsLeapYear(Year));
  67.         end;
  68.   else
  69.     Result := 0;
  70.   end;
  71. end;
  72.  
  73. function DefaultEpoch : Integer;
  74. var
  75.   ThisYear   : Word;
  76.   ThisMonth  : Word;
  77.   ThisDay    : Word;
  78. begin
  79.   DecodeDate(SysUtils.Date, ThisYear, ThisMonth, ThisDay);
  80.   Result := (ThisYear mod 100) * 100;                                  {!!.05}
  81. end;
  82.  
  83. function GetLeftButton : Byte;
  84. const
  85.   RLButton : array[Boolean] of Word = (VK_LBUTTON, VK_RBUTTON);
  86. begin
  87.   Result := RLButton[GetSystemMetrics(SM_SWAPBUTTON) <> 0];
  88. end;
  89.  
  90. procedure GetRGB(Clr : TColor; var IR, IG, IB : Byte);
  91. begin
  92.   IR := GetRValue(Clr);
  93.   IG := GetGValue(Clr);
  94.   IB := GetBValue(Clr);
  95. end;
  96.  
  97. function IsLeapYear(Year : Integer) : Boolean;
  98. begin
  99.   Result := (Year mod 4 = 0) and (Year mod 4000 <> 0) and
  100.     ((Year mod 100 <> 0) or (Year mod 400 = 0));
  101. end;
  102.  
  103. function Max(I, J : Integer) : Integer;
  104. begin
  105.   if I > J then
  106.     Result := I
  107.   else
  108.     Result := J;
  109. end;
  110.  
  111. function Min(I, J : Integer) : Integer;
  112. begin
  113.   if I < J then
  114.     Result := I
  115.   else
  116.     Result := J;
  117. end;
  118.  
  119. procedure FreeStrRes; far;
  120. begin
  121.   StrRes.Free;
  122.   StrRes := nil;
  123. end;
  124.  
  125. initialization
  126.   StrRes := TpsStringResource.Create(HInstance, 'ESSENTIALS_STRINGS_ENGLISH');
  127.  
  128. {$IFDEF Win32}
  129. finalization
  130.   FreeStrRes;
  131. {$ELSE}
  132.   AddExitProc(FreeStrRes);
  133. {$ENDIF}
  134. end.