home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / DFMTOOLS.ZIP / Delphi_DFM / Source / cdcUtils.pas next >
Encoding:
Pascal/Delphi Source File  |  1998-11-02  |  38.1 KB  |  1,128 lines

  1. unit cdcUtils;
  2. // Imported from Richard Library
  3. //          LoadFormPosition
  4. {
  5. >Look up function ShellExecute in the help file. (shellapi unit).
  6. >For ex:
  7. >ShellExecute(Handle,'open',PChar(Edit1.Text),'','',SW_SHOWNORMAL);
  8. >or
  9. >ShellExecute(Handle,'open', 'c:\doc\bar.doc' ,'','',SW_SHOWNORMAL);
  10. >
  11. >This has the same effect as double clicking the file in the explorer.        
  12. }
  13. interface
  14.  
  15. Uses
  16.   Classes, Controls, ComCtrls, Forms, Windows, Graphics, Grids, DB,
  17.   {$IFNDEF VCL3+}DBTables, {$ENDIF}
  18.   DBGrids,
  19.   cdcLibrary;
  20.  
  21. type
  22.    TRResult = (rrFail,rrNoMatch,rrBadParam,rrOK);
  23.  
  24. Const
  25.    MidNight : TDateTime = ((23+(59+59/60)/60)/24);
  26.  
  27. //Math Function not found in the Math unit -----------------------------------------------------------------------------}
  28. function MinInt(const A,B:Integer):Integer;
  29. function MaxInt(const A,B:Integer):Integer;
  30. function ExtractTotal(Const Value:String;Const e:Integer):Integer;
  31.  
  32. //Registration Function --------------------------------------------------------------------------------------------
  33. // Translate by Carlos de Cumont from code receive from A2i
  34. function  GetRegistration(Const MasterHKEY:Integer;Const MasterKey,Key:String):string;
  35. function  CheckRegistration(Const MasterHKey:Integer;Const MasterKey,Key:String):tRResult;
  36. Procedure WriteRegistration(Const MasterHKey:Integer;Const MasterKey,Key:String);
  37.  
  38. procedure CenterControlsInParent(const ControlArray :array of TControl);
  39. procedure CenterInParent(AParent : TWinControl);
  40. procedure CenterAllInParent(AParent : TWinControl;Offset:Integer);
  41. procedure CenterEachInParent(AParent : TWinControl);
  42. procedure CenterSizedInParent(AControl : TControl);
  43. procedure VCenterAllInParent(AParent : TWinControl;Offset:Integer);
  44.  
  45. procedure AlignControlWithHeader(AHeader : THeaderControl; ASectionIndex : Integer; AControl : TControl);
  46. procedure AlignControlWithColumn(AGrid : TCustomGrid; AColumnIndex : Integer; AControl : TControl);
  47. procedure AlignControlWithFieldColumn(AGrid : TCustomGrid; AField : TField; AControl : TControl);
  48.  
  49. function UniversalDecodeDate(DateFormat,DateString:String;var date:TDateTime):Boolean;
  50. function UniversalDecodeTime(TimeFormat,TimeString:String;var time:TDateTime):Boolean;
  51. function SecToDuration(Value:Integer):String;
  52.  
  53. function FirstDayOfMonth(aDate:TDate):TDateTime;
  54. function LastDayOfMonth(aDate:TDate):TDateTime;
  55. Procedure DayTimeToFromSunday(Const value:TDateTime;var fromSunday,fromMinuit:Integer);
  56. function DateToNr(value:TDateTime):Integer;
  57. function TrimRightDigit(Const AString : String):String;
  58. function MinToStr(Const Value: Integer):String;
  59. function IncString(Const Value:String;Const Idx:Integer):String;
  60. function EnsureSentenceTerminates(Sentence: String; Terminator: Char): String;
  61.  
  62. Procedure SplitTel(Const Value: String; Var Ptel,Tel: String);
  63. Procedure SplitTelFld(Const Value: String;Ptel,Tel: tField);
  64.  
  65. procedure PaintRainbow(Dc : HDC; {Canvas to paint to}
  66.                        x : integer; {Start position X}
  67.                        y : integer;  {Start position Y}
  68.                        Width : integer; {Width of the rainbow}
  69.                        Height : integer {Height of the rainbow};
  70.                        bVertical : bool; {Paint verticallty}
  71.                        WrapToRed : bool); {Wrap spectrum back to red}
  72.  
  73. {
  74.   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,0,nil,0);//OFF
  75.   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,0);//ON
  76. }
  77.  
  78. implementation
  79.  
  80. Uses SysUtils, Registry , Inifiles, Printers , Math;
  81.  
  82. {$IFDEF VER100}  // delphi 3 (version)
  83. Type
  84.   LongWord = Integer;
  85. {$ENDIF}
  86.  
  87. //{------------------------------------------------------------------------------}
  88.  
  89.  
  90. //{------------------------------------------------------------------------------}
  91. function FindGridColumn(AGrid : TDBGrid; AFieldName : String) : TColumn;
  92. var Counter : Integer;
  93. begin
  94. Result := nil;
  95. for Counter := 0 to AGrid.Columns.Count - 1 do
  96.     begin
  97.     if CompareText(AGrid.Columns[Counter].FieldName, AFieldName) = 0 then
  98.         begin
  99.         Result := AGrid.Columns[Counter];
  100.         Exit;
  101. end end end;
  102.  
  103. //{------------------------------------------------------------------------------}
  104. function GetGridColumn(AGrid : TDBGrid; AFieldName : String) : TColumn;
  105. begin
  106. Result := FindGridColumn(AGrid, AFieldName);
  107. if Result = nil then
  108.    raise Exception.Create('Cannot find ' + AGrid.Name + ' column for ' + AFieldName);
  109. end;
  110.  
  111. //{------------------------------------------------------------------------------}
  112. function OpenGridColumn(AGrid : TDBGrid; AFieldName : String) : TColumn;
  113. begin
  114. Result := FindGridColumn(AGrid, AFieldName);
  115. if Result = nil then
  116.     begin
  117.     Result := TColumn.Create(AGrid.Columns);
  118.     Result.FieldName := AFieldName;
  119. end end;
  120.  
  121. //{------------------------------------------------------------------------------}
  122. type
  123.    TCrackerGrid = class(TCustomGrid)
  124.    public
  125.        property GridLineWidth;
  126.        property ColWidths;
  127.    end;
  128.  
  129.    TCrackerDBGrid = class(TCustomDBGrid)
  130.    public
  131.        property Options;
  132.        property LeftCol;
  133.    end;
  134.  
  135. //{------------------------------------------------------------------------------}
  136. procedure AlignControlWithHeader(AHeader : THeaderControl; ASectionIndex : Integer; AControl : TControl);
  137. var i , OffSet : Integer;
  138. //    AParent : TWinControl;
  139. begin
  140. //By Carlos...
  141. if (AControl=nil) then Exit;
  142. Assert(ASectionIndex in [0..AHeader.Sections.Count-1]);
  143.  
  144. with AHeader do
  145.    begin
  146. //   AParent := AControl.Parent;
  147.    //Find the common parent ---------------------
  148.  
  149.    //Get the left position
  150.    OffSet:=0;
  151.    for i:=0 to ASectionIndex-1 do
  152.        Inc(OffSet,AHeader.Sections.Items[i].Width);
  153.  
  154.    //Move the Controls
  155.    AControl.SetBounds(OffSet, AControl.Top,
  156.                       AHeader.Sections.Items[ASectionIndex].Width, AControl.Height);
  157. end end;
  158.  
  159. //{------------------------------------------------------------------------------}
  160. procedure AlignControlWithColumn(AGrid : TCustomGrid; AColumnIndex : Integer; AControl : TControl);
  161. var Counter, ColumnLeft, ParentOffset : Integer;
  162.     AParent : TWinControl;
  163.     Offset : Integer;
  164. begin
  165. //By Carlos...
  166. if (AControl=nil) then Exit;
  167.  
  168. with TCrackerGrid(AGrid) do
  169.    begin
  170.    ColumnLeft := 0;
  171.    if (AGrid is TCustomDBGrid) and (dgIndicator in TCrackerDBGrid(AGrid).Options) then
  172.        begin
  173.        Inc(AColumnIndex);
  174.        Offset:=ColWidths[0];
  175.    end else
  176.        Offset:=0;
  177.  
  178.    if AColumnIndex < LeftCol then
  179.       begin
  180.       for Counter := 0 to LeftCol - 1 do
  181.           begin
  182.           Dec(ColumnLeft, ColWidths[Counter]);
  183.           Dec(ColumnLeft, GridLineWidth);
  184.       end;
  185.    end else begin
  186.       for Counter := LeftCol to AColumnIndex - 1 do
  187.           begin
  188.           Inc(ColumnLeft, ColWidths[Counter]);
  189.           Inc(ColumnLeft, GridLineWidth);
  190.           end;
  191.    AParent := AControl.Parent;
  192.    ParentOffset := 0;
  193.    while (AParent <> nil) do
  194.       begin
  195.       if (AParent = AGrid.Parent) then
  196.           begin
  197.           Inc(ColumnLeft, ParentOffset);
  198.           Break;
  199.       end else begin
  200.           Dec(ParentOffset, AParent.Left);
  201.           AParent := AParent.Parent;
  202.           end;
  203.       end;
  204.    end;
  205.    AControl.SetBounds(ColumnLeft + AGrid.Left + OffSet , AControl.Top,
  206.                       ColWidths[AColumnIndex], AControl.Height);
  207. end end;
  208.  
  209. //{------------------------------------------------------------------------------}
  210. procedure AlignControlWithFieldColumn(AGrid : TCustomGrid; AField : TField; AControl : TControl);
  211. var ThisColumn : TColumn;
  212. begin
  213. if (AField <> nil) and (AField.FieldName <> '') and (AGrid <>nil) and (AGrid is TDBGrid) then
  214.     begin
  215.     ThisColumn := FindGridColumn(TDBGrid(AGrid), AField.FieldName);
  216.     if ThisColumn <> nil then
  217.        AlignControlWithColumn(AGrid, ThisColumn.Index, AControl);
  218. end end;
  219.  
  220. //{------------------------------------------------------------------------------}
  221. procedure NotifyAllForms(AMsg, WParam, LParam : Integer);
  222. var Counter : Integer;
  223. begin
  224. for Counter := 0 to Screen.FormCount - 1 do
  225.    begin
  226.    SendMessage(Screen.Forms[Counter].Handle, AMsg, WParam, LParam);
  227.    end;
  228. end;
  229.  
  230. //-----------------------------------------------------------------------------------
  231. function IncString(Const Value:String;Const Idx:Integer):String;
  232. Var Str:String;
  233.    procedure BumpCharacter(Pointer : Integer);
  234.    begin
  235.    if Pointer <= 0 then
  236.        raise Exception.Create('Cannot increment first character in ' + Str);
  237.  
  238.    if (Str[Pointer] = 'z') then begin
  239.        BumpCharacter(Pointer - 1);
  240.        Str[Pointer] := 'A';
  241.    end else
  242.    if (Str[Pointer] = '9') then begin
  243.        BumpCharacter(Pointer - 1);
  244.        Str[Pointer] := '0';
  245.    end else
  246.        Str[Pointer] := Chr(Ord(Str[Pointer]) + 1)
  247.    end;
  248. begin
  249. Str:=Value;
  250. if Str = '' then
  251.    Str := '0'
  252. else
  253. if not (Str[1] in ['0'..'9']) then
  254.    BumpCharacter(Length(Str))
  255. else
  256.    try Str :=  IntToStr(StrToInt(Str) + 1);
  257.    except
  258.        {// I can't pick a StrToIntDef value that may not be a real value, so I have to use the exception   }
  259.        on EConvertError do begin
  260.            BumpCharacter(Length(Str));
  261.    end end;
  262. Result := Str;
  263. end;
  264.  
  265. //------------------------------------------------------------------------------
  266. function EnsureSentenceTerminates(Sentence: String; Terminator: Char): String;
  267. begin
  268.   if (Length(Sentence) > 0) and (Sentence[Length(Sentence)] <> Terminator) then
  269.     result := Sentence + Terminator
  270.   else
  271.     result := Sentence;
  272. end;
  273.  
  274.  
  275. {
  276. The following example demonstrates painting a color spectrum,
  277. and calculating the color of a given point on the spectrum.
  278. Two procedures are presented: PaintRainbow() and
  279. ColorAtRainbowPoint(). The PaintRainbow() procedure paints a
  280. spectrum from red to magenta if the WrapToRed parameter is
  281. false, or paint red to red if the WrapToRed parameter is true.
  282. The rainbow can progress either in a horizontal or
  283. vertical progression. The ColorAtRainbowPoint() function
  284. returns a TColorRef containing the color at a given point in
  285. the rainbow.
  286.  
  287. Example:
  288. }
  289.  
  290. procedure PaintRainbow(Dc : hDc; {Canvas to paint to}
  291.                        x : integer; {Start position X}
  292.                        y : integer;  {Start position Y}
  293.                        Width : integer; {Width of the rainbow}
  294.                        Height : integer {Height of the rainbow};
  295.                        bVertical : bool; {Paint verticallty}
  296.                        WrapToRed : bool); {Wrap spectrum back to red}
  297. var
  298.   i : integer;
  299.   ColorChunk : integer;
  300.   OldBrush : hBrush;
  301.   //OldPen : hPen;
  302.   r : integer;
  303.   g : integer;
  304.   b : integer;
  305.   Chunks : integer;
  306.   //ChunksMinus1 : integer;
  307.   pt : TPoint;
  308. begin
  309.   OffsetViewportOrgEx(Dc,
  310.                       x,
  311.                       y,
  312.                       pt);
  313.  
  314.   if WrapToRed = false then
  315.     Chunks := 5 else
  316.     Chunks := 6;
  317.   //ChunksMinus1 := Chunks - 1;
  318.  
  319.   if bVertical = false then
  320.     ColorChunk := Width div Chunks else
  321.     ColorChunk := Height div Chunks;
  322.  
  323.  {Red To Yellow}
  324.   r := 255;
  325.   b := 0;
  326.   for i := 0 to ColorChunk do begin
  327.     g:= (255 div ColorChunk) * i;
  328.     OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
  329.     if bVertical = false then
  330.       PatBlt(Dc, i, 0, 1, Height, PatCopy) else
  331.       PatBlt(Dc, 0, i, Width, 1, PatCopy);
  332.     DeleteObject(SelectObject(Dc, OldBrush));
  333.   end;
  334.  
  335.  {Yellow To Green}
  336.   g:=255;
  337.   b:=0;
  338.   for i := ColorChunk  to (ColorChunk * 2) do begin
  339.     r := 255 - (255 div ColorChunk) * (i - ColorChunk);
  340.     OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
  341.     if bVertical = false then
  342.       PatBlt(Dc, i, 0, 1, Height, PatCopy) else
  343.       PatBlt(Dc, 0, i, Width, 1, PatCopy);
  344.     DeleteObject(SelectObject(Dc, OldBrush));
  345.   end;
  346.  
  347.  {Green To Cyan}
  348.   r:=0;
  349.   g:=255;
  350.   for i:= (ColorChunk * 2) to (ColorChunk * 3) do begin
  351.     b := (255 div ColorChunk)*(i - ColorChunk * 2);
  352.     OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
  353.     if bVertical = false then
  354.       PatBlt(Dc, i, 0, 1, Height, PatCopy) else
  355.       PatBlt(Dc, 0, i, Width, 1, PatCopy);
  356.     DeleteObject(SelectObject(Dc,OldBrush));
  357.   end;
  358.  
  359.  {Cyan To Blue}
  360.   r := 0;
  361.   b := 255;
  362.   for i:= (ColorChunk * 3) to (ColorChunk * 4) do begin
  363.     g := 255 - ((255 div ColorChunk) * (i - ColorChunk * 3));
  364.     OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
  365.     if bVertical = false then
  366.       PatBlt(Dc, i, 0, 1, Height, PatCopy) else
  367.       PatBlt(Dc, 0, i, Width, 1, PatCopy);
  368.     DeleteObject(SelectObject(Dc, OldBrush));
  369.   end;
  370.  
  371.  {Blue To Magenta}
  372.   g := 0;
  373.   b := 255;
  374.   for i:= (ColorChunk * 4) to (ColorChunk * 5) do begin
  375.     r := (255 div ColorChunk) * (i - ColorChunk * 4);
  376.     OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
  377.     if bVertical = false then
  378.       PatBlt(Dc, i, 0, 1, Height, PatCopy) else
  379.       PatBlt(Dc, 0, i, Width, 1, PatCopy);
  380.     DeleteObject(SelectObject(Dc, OldBrush))
  381.   end;
  382.  
  383.   if WrapToRed <> false then begin
  384.    {Magenta To Red}
  385.     r := 255;
  386.     g := 0;
  387.     for i := (ColorChunk * 5) to ((ColorChunk * 6) - 1) do begin
  388.       b := 255 -((255 div ColorChunk) * (i - ColorChunk * 5));
  389.       OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r,g,b)));
  390.       if bVertical = false then
  391.         PatBlt(Dc, i, 0, 1, Height, PatCopy) else
  392.         PatBlt(Dc, 0, i, Width, 1, PatCopy);
  393.       DeleteObject(SelectObject(Dc,OldBrush));
  394.     end;
  395.   end;
  396.  
  397.  {Fill Remainder}
  398.   if (Width - (ColorChunk * Chunks) - 1 ) > 0 then begin
  399.     if WrapToRed <> false then begin
  400.       r := 255;
  401.       g := 0;
  402.       b := 0;
  403.     end else begin
  404.       r := 255;
  405.       g := 0;
  406.       b := 255;
  407.     end;
  408.     OldBrush := SelectObject(Dc, CreateSolidBrush(Rgb(r, g, b)));
  409.     if bVertical = false then
  410.       PatBlt(Dc,
  411.              ColorChunk * Chunks,
  412.              0,
  413.              Width - (ColorChunk * Chunks),
  414.              Height,
  415.              PatCopy) else
  416.       PatBlt(Dc,
  417.              0,
  418.              ColorChunk * Chunks,
  419.              Width,
  420.              Height - (ColorChunk * Chunks),
  421.              PatCopy);
  422.     DeleteObject(SelectObject(Dc,OldBrush));
  423.   end;
  424.   OffsetViewportOrgEx(Dc,
  425.                       Pt.x,
  426.                       Pt.y,
  427.                       pt);
  428. end;
  429.  
  430. function ColorAtRainbowPoint(ColorPlace : integer;
  431.                              RainbowWidth : integer;
  432.                              WrapToRed : bool) : TColorRef;
  433. var
  434.   ColorChunk : integer;
  435.   ColorChunkIndex : integer;
  436.   ColorChunkStart : integer;
  437. begin
  438.   if ColorPlace = 0 then begin
  439.     result := RGB(255, 0, 0);
  440.     exit;
  441.  end;
  442. {WhatChunk}
  443.   if WrapToRed <> false then
  444.     ColorChunk := RainbowWidth div 6 else
  445.     ColorChunk := RainbowWidth div 5;
  446.     ColorChunkStart := ColorPlace div ColorChunk;
  447.     ColorChunkIndex := ColorPlace mod ColorChunk;
  448.   case ColorChunkStart of
  449.    0 : result := RGB(255,
  450.                      (255 div ColorChunk) * ColorChunkIndex,
  451.                      0);
  452.    1 : result := RGB(255 - (255 div ColorChunk) * ColorChunkIndex,
  453.                      255,
  454.                      0);
  455.    2 : result := RGB(0, 255, (255 div ColorChunk) * ColorChunkIndex);
  456.    3 : result := RGB(0,
  457.                      255 - (255 div ColorChunk) * ColorChunkIndex,
  458.                      255);
  459.    4 : result := RGB((255 div ColorChunk) * ColorChunkIndex,
  460.                      0,
  461.                      255);
  462.    5 : result := RGB(255,
  463.                      0,
  464.                      255 - (255 div ColorChunk) * ColorChunkIndex);
  465.   else
  466.     if WrapToRed <> false then
  467.       result := RGB(255, 0, 0) else
  468.       result := RGB(255, 0, 255);
  469.   end;{Case}
  470. end;
  471.  
  472. {
  473. procedure TForm1.FormPaint(Sender: TObject);
  474. begin
  475.   PaintRainbow(Form1.Canvas.Handle,
  476.                0,
  477.                0,
  478.                Form1.ClientWidth,
  479.                Form1.ClientHeight,
  480.                false,
  481.                true);
  482.  
  483. end;
  484.  
  485. procedure TForm1.FormResize(Sender: TObject);
  486. begin
  487.   InvalidateRect(Form1.Handle, nil, false);
  488. end;
  489.  
  490. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  491.   Shift: TShiftState; X, Y: Integer);
  492. var
  493.   Color : TColorRef;
  494. begin
  495.   Color := ColorAtRainbowPoint(y,
  496.                                Form1.ClientWidth,
  497.                                true);
  498.   ShowMessage(IntToStr(GetRValue(Color)) + #32 +
  499.               IntToStr(GetGValue(Color)) + #32 +
  500.               IntToStr(GetBValue(Color)));
  501. end;
  502. }
  503.  
  504. //------------------------------------------------------------------------------
  505. procedure DivMod(Dividend: Integer; Divisor: Word;var Result, Remainder: Word);
  506. asm
  507.         PUSH    EBX
  508.         MOV     EBX,EDX
  509.         MOV     EDX,EAX
  510.         SHR     EDX,16
  511.         DIV     BX
  512.         MOV     EBX,Remainder
  513.         MOV     [ECX],AX
  514.         MOV     [EBX],DX
  515.         POP     EBX
  516. end;
  517.  
  518. //------------------------------------------------------------------------------
  519. function UniversalDecodeTime(TimeFormat,TimeString:String;var time:TDateTime):Boolean;
  520. var Hour, Min, Sec, MSec : Word;
  521.     i:Integer;
  522. begin
  523. TimeFormat:=lowerCase(TimeFormat);
  524. try MSec:=0;
  525.     //Decode Sec !!!!!!!!!!!!! //      TimeFormat  : String = 'ss:mm:hh';          //00:01:27
  526.     i:=pos('ss',TimeFormat);
  527.     if i<=0 then Exception.Create('Invalid Time Format :'+TimeFormat+':'+TimeString);
  528.     sec:=StrToInt(copy(TimeString,i,2));
  529.     //Decode Min !!!!!!!!!!!!! //      TimeFormat  : String = 'ss:mm:hh';          //00:01:27
  530.     i:=pos('mm',TimeFormat);
  531.     if i<=0 then Exception.Create('Invalid Time Format :'+TimeFormat+':'+TimeString);
  532.     min:=StrToInt(copy(TimeString,i,2));
  533.     //Decode Hour !!!!!!!!!!!!! //      TimeFormat  : String = 'ss:mm:hh';          //00:01:27
  534.     i:=pos('hh',TimeFormat);
  535.     if i<=0 then Exception.Create('Invalid Time Format :'+TimeFormat+':'+TimeString);
  536.     hour:=StrToInt(copy(TimeString,i,2));
  537.     time:=EncodeTime(Hour, Min, Sec, MSec);
  538.     result:=true;
  539. except
  540.     result:=false;
  541. end end;
  542.  
  543. //------------------------------------------------------------------------------
  544. function UniversalDecodeDate(DateFormat,DateString:String;var date:TDateTime):Boolean;
  545. var day, month, year: Word;
  546.     i:Integer;
  547. begin
  548. DateFormat:=lowerCase(DateFormat);
  549. try //Decode day !!!!!!!!!!!!! DateFormat  : String = 'dd/mm/yyyy';               //08-08-1997
  550.     i:=pos('dd',DateFormat);
  551.     if i<=0 then Exception.Create('Invalid Date Format :'+DateFormat);
  552.     day:=StrToInt(copy(dateString,i,2));
  553.     //Decode month !!!!!!!!!!!!! DateFormat  : String = 'dd/mm/yyyy';               //08-08-1997
  554.     i:=pos('mm',DateFormat);
  555.     if i<=0 then Exception.Create('Invalid Date Format :'+DateFormat);
  556.     month:=StrToInt(copy(dateString,i,2));
  557.     //Decode year !!!!!!!!!!!!! DateFormat  : String = 'dd/mm/yyyy';               //08-08-1997
  558.     i:=pos('yyyy',DateFormat);
  559.     if i<=0 then
  560.        begin
  561.        i:=pos('yy',DateFormat);
  562.        if i<=0 then Exception.Create('Invalid Date Format :'+DateFormat);
  563.        year:=StrToInt(copy(dateString,i,2));
  564.        if year>50 then year:=year+1900;
  565.     end else
  566.        year:=StrToInt(copy(dateString,i,4));
  567.     Date:=EncodeDate(year,month,day);
  568.     result:=true;
  569. except
  570.     result:=false;
  571. end end;
  572.  
  573. //------------------------------------------------------------------------------
  574. //Transform a Date to a Nr YYYYMMDD
  575. function DateToNr(value:TDateTime):Integer;
  576. var Year,Month,Day:Word;
  577. begin
  578. DecodeDate(Value, Year,Month,Day);
  579. Result:=Year*100+Month;
  580. end;
  581.  
  582. //------------------------------------------------------------------------------
  583. function TrimRightDigit(Const AString : String):String;
  584. begin
  585. result:=AString;
  586. while (Length(result)>0)and(result[Length(result)] in ['0'..'9']) do
  587.    System.Delete(result,Length(result),1)
  588. end;
  589.  
  590. //------------------------------------------------------------------------------
  591. function MinToStr(Const Value: Integer):String;
  592. var Min,Sec,Hour,i:Integer;
  593. begin
  594. Hour:=value div (60*60);
  595. i:=value mod (60*60);
  596. Min:=i div 60;
  597. Sec:=i div 60;
  598. if hour>0 then
  599.    result :=format('%dh%2d''%2d"',[hour,min,sec])
  600. else
  601. if Min>0 then
  602.    result :=format('%2d''%2d"',[min,sec])
  603. else
  604.    result :=format('%2d"',[sec])
  605. end;
  606.  
  607. //------------------------------------------------------------------------------
  608. Procedure SplitTelFld(Const Value: String;Ptel,Tel: tField);
  609. Var
  610.    Stel,SPtel : String;
  611. Begin
  612.    SplitTel(Value,SPtel,Stel);
  613.    Ptel.ASstring:=SPtel;
  614.    Tel.ASstring:= STel;
  615. end;
  616.  
  617. //------------------------------------------------------------------------------
  618. Procedure SplitTel(Const Value: String; Var Ptel,Tel: String);
  619.    function deleteNoneDigit(Var V: String): String;
  620.    Var    i:Integer;
  621.    Begin
  622.      For i:=1 to Length(V) do Begin
  623.          if not (V[i] in ['0'..'9']) then
  624.             Delete(V,i,1)
  625.      end;
  626.      Result :=V;
  627.    End;
  628.  
  629. Var i : Integer;
  630. Begin
  631. Tel := Value;
  632. if (Tel='') or (Tel[1]<>'0') then
  633.    Begin
  634.    Tel:=deleteNoneDigit(Tel);
  635.    end
  636. else
  637.   Begin
  638.   for i:=1 to Length(Tel) do begin
  639.      if not (Tel[i] in ['0'..'9']) then
  640.         Begin
  641.         Ptel := Copy(Tel,1,i-1);
  642.         Delete(Tel,1,i);
  643.         Tel  := deleteNoneDigit(Tel);
  644.         Break;
  645.         end
  646.      end;
  647.   //More code
  648.   end
  649. End;
  650.  
  651.  
  652. //------------------------------------------------------------------------------
  653. //; DateTime Seconds, proc to calc the number of seconds from Sunday 00:00:00
  654. //paraodox --> Proc DTseconds(dd SmallInt, tt time) LongInt
  655. Procedure DayTimeToFromSunday(Const value:TDateTime;var fromSunday,fromMinuit:Integer);
  656. Var Hour, Min, Sec, MSec:Word;
  657. begin
  658. //Calcul time elapsed from SunDay 00:00
  659. //and with the tarif definiton look if DayTime is in the WeekEnd Time !!!!!!!!!!!!!!
  660. //The DayOfWeek function returns the day of the week of the specified date as an integer between 1 and 7. Sunday is the first day of the week and Saturday is the seventh.        DayOfWeek
  661. DecodeTime(Value, Hour, Min, Sec, MSec);
  662. fromMinuit:=hour*60*60+min*60+sec;
  663. fromSunday:=(DayOfWeek(value)-1)*24*60*60+fromMinuit
  664. end;
  665.  
  666. //-----------------------------------------------------------------------------}
  667. function FirstDayOfMonth(aDate:TDate):TDateTime;
  668. Begin
  669. result:=Trunc(cdcUtils.LastDayOfMonth(now-39)+1);
  670. End;
  671.  
  672. //-----------------------------------------------------------------------------}
  673. function LastDayOfMonth(aDate:TDate):TDateTime;
  674. var aDay,aMonth,aYear:Word;
  675. begin
  676.   DecodeDate(aDate,aYear,aMonth,aDay);
  677.   if aMonth=12 then
  678.      result:=EncodeDate(aYear+1,1,1)-1+MidNight
  679.   else
  680.      result:=EncodeDate(aYear,aMonth+1,1)-1+MidNight
  681. end;
  682.  
  683. //-----------------------------------------------------------------------------}
  684. function SecToDuration(Value:Integer):String;
  685. var i,Hour,Min,Sec:Word;
  686. begin
  687.    Hour:=value div (60*60);
  688.    i:=value mod (60*60);
  689.    DivMod(i,60,Min,Sec);
  690.    if hour>0 then
  691.       Result :=format('%dh%2d''%2d"',[hour,min,sec])
  692.    else
  693.    if Min>0 then
  694.       Result :=format('%2d''%2d"',[min,sec])
  695.    else
  696.       Result :=format('%2d"',[sec])
  697. end;
  698.  
  699. {------------------------------------------------------------------------------}
  700. procedure CenterControlsInParent(const ControlArray :array of TControl);
  701. var Counter : Integer;
  702.     ControlWidth, SpacerWidth : Integer;
  703. begin
  704. if not ControlArray[0].Parent.Showing then
  705.    Exit;
  706.  
  707. ControlWidth := 0;
  708. for Counter := Low(ControlArray) to High(ControlArray) do
  709.     Inc(ControlWidth, ControlArray[Counter].Width);
  710.  
  711. {  Assuming at least one element: ControlArray[0]   }
  712. SpacerWidth := (ControlArray[0].Parent.ClientWidth - ControlWidth) div
  713.                ((High(ControlArray) - Low(ControlArray))
  714.                + 2);
  715.  
  716. ControlWidth := 0;
  717. for Counter := Low(ControlArray) to High(ControlArray) do
  718.     begin
  719.     Inc(ControlWidth, SpacerWidth);
  720.     with ControlArray[Counter] do
  721.        begin
  722.        Left := ControlWidth;
  723.        Inc(ControlWidth, Width);
  724.        end;
  725.     end;
  726. end;
  727.  
  728. {------------------------------------------------------------------------------}
  729. procedure CenterInParent(AParent : TWinControl);
  730. var Counter : Integer;
  731.     ControlWidth, SpacerWidth : Integer;
  732.     ControlList : TList;
  733.  
  734.    procedure AddControl(AControl : TControl);
  735.    var Counter : Integer;
  736.    begin
  737.    for Counter := 0 to ControlList.Count - 1 do
  738.       begin
  739.       if AControl.Left < TControl(ControlList[Counter]).Left then
  740.          begin
  741.          ControlList.Insert(Counter, AControl);
  742.          Exit;
  743.          end;
  744.       end;
  745.    ControlList.Add(AControl);
  746.    end;
  747.  
  748. begin
  749. ControlList := TList.Create;
  750. try
  751.     ControlWidth := 0;
  752.     for Counter := 0 to AParent.ControlCount - 1 do
  753.        begin
  754.        if AParent.Controls[Counter].Visible then
  755.           begin
  756.           Inc(ControlWidth, AParent.Controls[Counter].Width);
  757.           AddControl(AParent.Controls[Counter]);
  758.           end;
  759.        end;
  760.     SpacerWidth := (AParent.ClientWidth - ControlWidth) div
  761.                    (ControlList.Count + 1);
  762.     ControlWidth := 0;
  763.     for Counter := 0 to ControlList.Count - 1 do
  764.         begin
  765.         Inc(ControlWidth, SpacerWidth);
  766.         with TControl(ControlList[Counter]) do
  767.            begin
  768.            Left := ControlWidth;
  769.            Inc(ControlWidth, Width);
  770.            end;
  771.         end;
  772. finally
  773.     ControlList.Free;
  774. end end;
  775.  
  776. {------------------------------------------------------------------------------}
  777. procedure VCenterAllInParent(AParent : TWinControl;Offset:Integer);
  778. var Counter : Integer;
  779.     ControlHeight, SpacerHeight : Integer;
  780.     ControlList : TList;
  781.  
  782.    procedure AddControl(AControl : TControl);
  783.    var Counter : Integer;
  784.    begin
  785.    for Counter := 0 to ControlList.Count - 1 do
  786.       begin
  787.       if AControl.Left < TControl(ControlList[Counter]).Left then
  788.          begin
  789.          ControlList.Insert(Counter, AControl);
  790.          Exit;
  791.          end;
  792.       end;
  793.    ControlList.Add(AControl);
  794.    end;
  795.  
  796. begin
  797. ControlList := TList.Create;
  798. try
  799.     ControlHeight := 0;
  800.     for Counter := 0 to AParent.ControlCount - 1 do
  801.        begin
  802.        if AParent.Controls[Counter].Visible then
  803.           begin
  804.           Inc(ControlHeight, AParent.Controls[Counter].Height);
  805.           AddControl(AParent.Controls[Counter]);
  806.           end;
  807.        end;
  808.     SpacerHeight := (AParent.ClientHeight - ControlHeight -Offset -Offset ) div
  809.                    (ControlList.Count - 1);
  810.     ControlHeight := 0;
  811.     for Counter := 0 to ControlList.Count - 1 do
  812.         begin
  813.         if Counter=0 then
  814.            Inc(ControlHeight, Offset)
  815.         else
  816.         if Counter=ControlList.Count - 1 then
  817.            ControlHeight:=AParent.ClientHeight-Offset-TControl(ControlList[Counter]).Height
  818.         else
  819.            Inc(ControlHeight, SpacerHeight);
  820.         with TControl(ControlList[Counter]) do
  821.            begin
  822.            top := ControlHeight;
  823.            Inc(ControlHeight, Height);
  824.            end;
  825.         end;
  826. finally
  827.     ControlList.Free;
  828. end end;
  829.  
  830. {------------------------------------------------------------------------------}
  831. procedure CenterAllInParent(AParent : TWinControl;Offset:Integer);
  832. var Counter : Integer;
  833.     ControlWidth, SpacerWidth : Integer;
  834.     ControlList : TList;
  835.  
  836.    procedure AddControl(AControl : TControl);
  837.    var Counter : Integer;
  838.    begin
  839.    for Counter := 0 to ControlList.Count - 1 do
  840.       begin
  841.       if AControl.Left < TControl(ControlList[Counter]).Left then
  842.          begin
  843.          ControlList.Insert(Counter, AControl);
  844.          Exit;
  845.          end;
  846.       end;
  847.    ControlList.Add(AControl);
  848.    end;
  849.  
  850. begin
  851. ControlList := TList.Create;
  852. try
  853.     ControlWidth := 0;
  854.     for Counter := 0 to AParent.ControlCount - 1 do
  855.        begin
  856.        if AParent.Controls[Counter].Visible then
  857.           begin
  858.           Inc(ControlWidth, AParent.Controls[Counter].Width);
  859.           AddControl(AParent.Controls[Counter]);
  860.           end;
  861.        end;
  862.     SpacerWidth := (AParent.ClientWidth - ControlWidth -Offset -Offset ) div
  863.                    (ControlList.Count - 1);
  864.     ControlWidth := 0;
  865.     for Counter := 0 to ControlList.Count - 1 do
  866.         begin
  867.         if Counter=0 then
  868.            Inc(ControlWidth, Offset)
  869.         else
  870.         if Counter=ControlList.Count - 1 then
  871.            ControlWidth:=AParent.ClientWidth-Offset-TControl(ControlList[Counter]).Width
  872.         else
  873.            Inc(ControlWidth, SpacerWidth);
  874.         with TControl(ControlList[Counter]) do
  875.            begin
  876.            Left := ControlWidth;
  877.            Inc(ControlWidth, Width);
  878.            end;
  879.         end;
  880. finally
  881.     ControlList.Free;
  882. end end;
  883.  
  884. {------------------------------------------------------------------------------}
  885. procedure CenterEachInParent(AParent : TWinControl);
  886. var Counter : Integer;
  887. begin
  888. for Counter := 0 to AParent.ControlCount - 1 do
  889.    begin
  890.    with AParent.Controls[Counter] do
  891.        begin
  892.        Left := (Parent.ClientWidth - Width) div 2;
  893.        end;
  894.    end;
  895. end;
  896.  
  897. {------------------------------------------------------------------------------}
  898. procedure CenterSizedInParent(AControl : TControl);
  899. begin
  900.    AControl.Width := (AControl.Parent.Width - (AControl.Left * 2));
  901. end;
  902.  
  903. {------------------------------------------------------------------------------}
  904. //   crc32tab and UPDC32
  905. //   Copyright (C) 1986 Gary S. Brown.
  906. //   used by permission
  907. //static unsigned long crc32tab[] = { /* CRC polynomial $EDB88320  */
  908. Const crc32tab : Array[0..255] of Longword  =
  909.    ($00000000, $77073096, $EE0E612C, $990951BA, $076DC419, $706AF48F, $E963A535, $9E6495A3,
  910.     $0EDB8832, $79DCB8A4, $E0D5E91E, $97D2D988, $09B64C2B, $7EB17CBD, $E7B82D07, $90BF1D91,
  911.     $1DB71064, $6AB020F2, $F3B97148, $84BE41DE, $1ADAD47D, $6DDDE4EB, $F4D4B551, $83D385C7,
  912.     $136C9856, $646BA8C0, $FD62F97A, $8A65C9EC, $14015C4F, $63066CD9, $FA0F3D63, $8D080DF5,
  913.     $3B6E20C8, $4C69105E, $D56041E4, $A2677172, $3C03E4D1, $4B04D447, $D20D85FD, $A50AB56B,
  914.     $35B5A8FA, $42B2986C, $DBBBC9D6, $ACBCF940, $32D86CE3, $45DF5C75, $DCD60DCF, $ABD13D59,
  915.     $26D930AC, $51DE003A, $C8D75180, $BFD06116, $21B4F4B5, $56B3C423, $CFBA9599, $B8BDA50F,
  916.     $2802B89E, $5F058808, $C60CD9B2, $B10BE924, $2F6F7C87, $58684C11, $C1611DAB, $B6662D3D,
  917.     $76DC4190, $01DB7106, $98D220BC, $EFD5102A, $71B18589, $06B6B51F, $9FBFE4A5, $E8B8D433,
  918.     $7807C9A2, $0F00F934, $9609A88E, $E10E9818, $7F6A0DBB, $086D3D2D, $91646C97, $E6635C01,
  919.     $6B6B51F4, $1C6C6162, $856530D8, $F262004E, $6C0695ED, $1B01A57B, $8208F4C1, $F50FC457,
  920.     $65B0D9C6, $12B7E950, $8BBEB8EA, $FCB9887C, $62DD1DDF, $15DA2D49, $8CD37CF3, $FBD44C65,
  921.     $4DB26158, $3AB551CE, $A3BC0074, $D4BB30E2, $4ADFA541, $3DD895D7, $A4D1C46D, $D3D6F4FB,
  922.     $4369E96A, $346ED9FC, $AD678846, $DA60B8D0, $44042D73, $33031DE5, $AA0A4C5F, $DD0D7CC9,
  923.     $5005713C, $270241AA, $BE0B1010, $C90C2086, $5768B525, $206F85B3, $B966D409, $CE61E49F,
  924.     $5EDEF90E, $29D9C998, $B0D09822, $C7D7A8B4, $59B33D17, $2EB40D81, $B7BD5C3B, $C0BA6CAD,
  925.     $EDB88320, $9ABFB3B6, $03B6E20C, $74B1D29A, $EAD54739, $9DD277AF, $04DB2615, $73DC1683,
  926.     $E3630B12, $94643B84, $0D6D6A3E, $7A6A5AA8, $E40ECF0B, $9309FF9D, $0A00AE27, $7D079EB1,
  927.     $F00F9344, $8708A3D2, $1E01F268, $6906C2FE, $F762575D, $806567CB, $196C3671, $6E6B06E7,
  928.     $FED41B76, $89D32BE0, $10DA7A5A, $67DD4ACC, $F9B9DF6F, $8EBEEFF9, $17B7BE43, $60B08ED5,
  929.     $D6D6A3E8, $A1D1937E, $38D8C2C4, $4FDFF252, $D1BB67F1, $A6BC5767, $3FB506DD, $48B2364B,
  930.     $D80D2BDA, $AF0A1B4C, $36034AF6, $41047A60, $DF60EFC3, $A867DF55, $316E8EEF, $4669BE79,
  931.     $CB61B38C, $BC66831A, $256FD2A0, $5268E236, $CC0C7795, $BB0B4703, $220216B9, $5505262F,
  932.     $C5BA3BBE, $B2BD0B28, $2BB45A92, $5CB36A04, $C2D7FFA7, $B5D0CF31, $2CD99E8B, $5BDEAE1D,
  933.     $9B64C2B0, $EC63F226, $756AA39C, $026D930A, $9C0906A9, $EB0E363F, $72076785, $05005713,
  934.     $95BF4A82, $E2B87A14, $7BB12BAE, $0CB61B38, $92D28E9B, $E5D5BE0D, $7CDCEFB7, $0BDBDF21,
  935.     $86D3D2D4, $F1D4E242, $68DDB3F8, $1FDA836E, $81BE16CD, $F6B9265B, $6FB077E1, $18B74777,
  936.     $88085AE6, $FF0F6A70, $66063BCA, $11010B5C, $8F659EFF, $F862AE69, $616BFFD3, $166CCF45,
  937.     $A00AE278, $D70DD2EE, $4E048354, $3903B3C2, $A7672661, $D06016F7, $4969474D, $3E6E77DB,
  938.     $AED16A4A, $D9D65ADC, $40DF0B66, $37D83BF0, $A9BCAE53, $DEBB9EC5, $47B2CF7F, $30B5FFE9,
  939.     $BDBDF21C, $CABAC28A, $53B39330, $24B4A3A6, $BAD03605, $CDD70693, $54DE5729, $23D967BF,
  940.     $B3667A2E, $C4614AB8, $5D681B02, $2A6F2B94, $B40BBE37, $C30C8EA1, $5A05DF1B, $2D02EF8D
  941.     );
  942.  
  943. //{------------------------------------------------------------------------------}
  944. function GetUnKnowData(Const f:TRegistry;const Name: string; Buffer: Pointer;BufSize: Integer): Integer;
  945. var //RegData: TRegDataType;
  946.     DataType: Integer;
  947. begin
  948.     DataType := REG_NONE;
  949.     If RegQueryValueEx(f.CurrentKey, PChar(Name), nil, @DataType, PByte(Buffer),@BufSize) <> ERROR_SUCCESS then
  950.        Result := 0 //e ERegistryException.Create('Unable to get data for '+Name);
  951.     else
  952.        Result := BufSize;
  953. end;
  954.  
  955. //{------------------------------------------------------------------------------}
  956. //#define UPDC32(c, crc) (crc32tab[((int)(crc) ^ (c)) & $ff] ^ (((crc) >> 8) & $00FFFFFFL))
  957. //Void CreatePartialCRC(Uint32& crc,buffer , Int32 count)
  958. Procedure CreatePartialCRC(Const buffer:LongWord;Const Count:Word;var crc:LongWord);
  959. Type PInt = ^LongWord;
  960. Var i:Word;
  961. begin
  962.   //for (Int32 i = 0; i < count; i++)
  963.   //     crc = UPDC32((int)(buffer[i]), crc);
  964.   for i := 0 to count-1 do
  965.       crc:=(crc32tab[(crc xor (PInt(Buffer+i)^)) and $ff]) xor ((crc shl 8)and($00FFFFFF))
  966. end;
  967.  
  968. //****************************************************************************
  969. // * FUNCTION     : RC GetLocalMachineID(ConstStr programName, CString& lmid)
  970. // * DESCRIPTION  : Generates the LMID by combining the _programName_ with
  971. // *                various features of the machine (ex. system bios, cpu id)
  972. // ***************************************************************************/
  973. TYPE
  974.   Tos = (TOS_WIN95 , TOS_WINNT);
  975. function GetLocalMachineID(Const os:tOS;Const MasterKey,Key:String;Var lmid:String):boolean;
  976. var k,s:String;
  977.     buffer:Array[Word] of Char;
  978.     l:Word;
  979.     fRegistry:TRegistry;
  980.     crc:LongWord;
  981. begin
  982. lmid:='';
  983. fRegistry:=TRegistry.create;
  984. try s:='';
  985.     fRegistry.RootKey:=HKEY_LOCAL_MACHINE;
  986.     // get win nt product id
  987.     IF OS = TOS_WINNT THEN
  988.        k:='SOFTWARE\Microsoft\Windows NT\CurrentVersion'
  989.     ELSE
  990.        k:='SOFTWARE\Microsoft\Windows\CurrentVersion';
  991.     fRegistry.OpenKey(k,false);
  992.     s:=s+fRegistry.ReadString('ProductId');
  993.     fRegistry.CloseKey;
  994.     // cpu id
  995.     k:='HARDWARE\DESCRIPTION\System\CentralProcessor\0';
  996.     fRegistry.OpenKey(k,false);
  997.     s:=s+fRegistry.ReadString('Identifier');
  998.     fRegistry.CloseKey;
  999.     // system bios
  1000.     k:='HARDWARE\DESCRIPTION\System';
  1001.     fRegistry.OpenKey(k,false);
  1002.     // video bios
  1003.     l:=GetUnKnowData(fRegistry,'VideoBiosVersion',@Buffer,high(word));
  1004.     buffer[l]:=#0;
  1005.     s:=s+buffer;
  1006.     l:=GetUnKnowData(fRegistry,'SystemBiosVersion',@Buffer,high(word));
  1007.     buffer[l]:=#0;
  1008.     s:=s+buffer;
  1009.     fRegistry.CloseKey;
  1010.     // it is possible that one or more of the values do not exist
  1011.     // if ALL of them do not exist, the LMID cannot be generated
  1012.     if(s='') then
  1013.        result:=false
  1014.     else
  1015.        Begin
  1016.        // create a 32-bit numerical CRC value from the string
  1017.        s:=UpperCase(Key)+s;
  1018.        crc:=$ffffffff;
  1019.        CreatePartialCRC(Integer(Pchar(s)),length(s),crc);
  1020.        lmid:=Format('%02x%02x%02x%02x',[HIBYTE(HIWORD(crc)),LOBYTE(HIWORD(crc)),HIBYTE(LOWORD(crc)),LOBYTE(LOWORD(crc))]);
  1021.        //return RC_OK;
  1022.        result:=true
  1023.        end;
  1024. finally fRegistry.free;
  1025. end end;
  1026.  
  1027. //****************************************************************************
  1028. // * FUNCTION     : RC CheckRegistration(ConstStr programName)
  1029. // * DESCRIPTION  : Checks to see if the LMID value in the registry matches the
  1030. // *                  generated LMID.
  1031. // ***************************************************************************/
  1032. function CheckRegistration(Const MasterHKey:Integer;Const MasterKey,Key:String):tRResult;
  1033. Var s,lmid:String;
  1034. begin
  1035.    s:=GetRegistration(MasterHKEY,MasterKey,Key);
  1036.    if s='' then
  1037.       result:=rrFail
  1038.    else
  1039.    if not GetLocalMachineID(TOS_WIN95,MasterKey,Key,lmid) then
  1040.       result:=rrBadParam
  1041.    else
  1042.    if s<>lmid then
  1043.       result:=rrNoMatch
  1044.    else
  1045.       result:=rrOK
  1046. end;
  1047.  
  1048. //{------------------------------------------------------------------------------}
  1049. //****************************************************************************
  1050. // * PROCEDURE    : Void GetRegistration(ConstStr programName, CString& value)
  1051. // * DESCRIPTION  : Retrieves the "LMID" (Local Machine ID) value of
  1052. // *                  HKEY_LOCAL_MACHINE\SOFTWARE\A2i\_programName_ in the registry.
  1053. // ***************************************************************************/
  1054. function GetRegistration(Const MasterHKEY:Integer;Const MasterKey,Key:String):string;
  1055. var fRegistry:TRegistry;
  1056. begin
  1057. fRegistry:=TRegistry.create;
  1058. try
  1059.     fRegistry.RootKey:=MasterHKEY;
  1060.     fRegistry.OpenKey(MasterKey,false);
  1061.     result:=fRegistry.ReadString(Format('%sLMID',[Key]));
  1062. finally fRegistry.free;
  1063. end end;
  1064.  
  1065. // ***************************************************************************/
  1066. Procedure WriteRegistration(Const MasterHKey:Integer;Const MasterKey,Key:String);
  1067. var fRegistry:TRegistry;
  1068.     s:String;
  1069. begin
  1070. if GetLocalMachineID(TOS_WIN95,MasterKey,Key,s) then
  1071.    begin
  1072.    fRegistry:=TRegistry.create;
  1073.    try fRegistry.RootKey:=MasterHKey;
  1074.        fRegistry.OpenKey(MasterKey,True);
  1075.        fRegistry.WriteString(Format('%sLMID',[Key]),s);
  1076.    finally fRegistry.free;
  1077.    end end
  1078. else
  1079.    Raise Exception.Create('Unable to register the program');
  1080. end;
  1081.  
  1082. //Math Function not found in the Math unit -----------------------------------------------------------------------------}
  1083. function MinInt(const A,B:Integer):Integer;
  1084. begin
  1085. if A<=B then
  1086.    Result := A
  1087. else
  1088.    Result := B
  1089. end;
  1090.  
  1091. //{------------------------------------------------------------------------------}
  1092. function MaxInt(const A,B:Integer):Integer;
  1093. begin
  1094. if A>=B then
  1095.    Result := A
  1096. else
  1097.    Result := B
  1098. end;
  1099.  
  1100. //{------------------------------------------------------------------------------}
  1101. function ExtractTotal(Const Value:String;Const e:Integer):Integer;
  1102. Var p,l,ll,dec:Integer;  s:String;
  1103. Begin
  1104. Result:=0;
  1105. l:=Length(Value);
  1106. if l=0 then
  1107.    exit;
  1108. p:=Pos(Value,'.');
  1109. if p>0 then
  1110.    begin
  1111.    //Extract decimal part
  1112.    s:=System.Copy(Value,p,l-p-1);
  1113.    ll:=length(s);
  1114.    dec:=StrToIntDef(s,0);
  1115.    if ll>0 then
  1116.       dec:=Round(dec*IntPower(10,e)/IntPower(10,ll));
  1117.    s:=System.Copy(Value,0,p-1);
  1118.    result:=dec
  1119.    end
  1120. else s:=Value;
  1121. result:=Round(StrToIntDef(s,0)*IntPower(10,e)+Result)
  1122. end;
  1123.  
  1124.  
  1125. end.
  1126.  
  1127.  
  1128.