home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / zkuste / delphi / WhiteAnts / PROGRESS.ZIP / DEMOOPS.PAS next >
Encoding:
Pascal/Delphi Source File  |  1997-01-10  |  2.0 KB  |  79 lines

  1. unit DemoOps;
  2.  
  3. { implements some demo operations which demonstrate the
  4.   use of the TProgressor / TProgressObserver classes }
  5. interface
  6.  
  7. procedure LengthyOperation;
  8. { The only thing LengthyOperation really does is wait for some time in some levels }
  9.  
  10.  
  11. implementation
  12.  
  13. uses SysUtils, WinProcs, Forms, Progress;
  14.  
  15. { delay approx ms milli seconds }
  16. procedure Delay(Ms: LongInt);
  17. var EndTime: LongInt;
  18. begin
  19.   EndTime := GetTickCount + MS;                       
  20.   while GetTickCount < EndTime do Application.ProcessMessages;
  21. end;
  22.  
  23. procedure SubOperation(Sub: Integer);
  24. var I: Integer;
  25. begin
  26.   { start sub level of operation }
  27.   TProgressor.Instance.StartProgress(0, Format('Running sub %d', [Sub]));
  28.   try
  29.     { protect again against exceptions which might cause us to remain busy forever }
  30.     for I := 0 to 100 do
  31.     begin
  32.       { simulate activity }
  33.       Delay(50);
  34.       { update progress }
  35.       TProgressor.Instance.Progress := I;
  36.       { check is user aborted operation }
  37.       if TProgressor.Instance.Aborted then
  38.         Exit;
  39.     end;
  40.     Delay(50);
  41.   finally
  42.     { reset busy state }
  43.     TProgressor.Instance.EndProgress;
  44.   end;
  45. end;
  46.  
  47. procedure LengthyOperation;
  48. var I: Integer;
  49. begin
  50.   TProgressor.Instance.StartProgress(0, 'Running main loop');
  51.   { protect progress with finally, or progress might remain busy forever
  52.     if an exception is raised somewhere inside the operation }
  53.   try
  54.     for I := 0 to 3 do
  55.     begin
  56.       { simulate main loop level activity }
  57.       Delay(500);
  58.  
  59.       { simulate sub activity }
  60.       SubOperation(I);
  61.  
  62.       { check whether user aborted operation or closed application.
  63.         Test this by closing the application while the operation is running }
  64.       if TProgressor.Instance.Aborted then
  65.       { exit will be caught by finally }
  66.         Exit;
  67.       { update progress }
  68.       TProgressor.Instance.Progress := 25 * (I + 1);
  69.     end;
  70.     Delay(500);
  71.   finally
  72.     { reset busy state }
  73.     TProgressor.Instance.EndProgress;
  74.   end;
  75. end;
  76.  
  77.  
  78. end.
  79.