ProgressHintFrm.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. unit ProgressHintFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, Gauges, StdCtrls, ExtCtrls, Math;
  6. type
  7. TProgressHintForm = class(TForm)
  8. Shape: TShape;
  9. gProgress: TGauge;
  10. gSubProgress: TGauge;
  11. lblProgressHint: TLabel;
  12. lblSubProgressHint: TLabel;
  13. lblMainHint: TLabel;
  14. lblPrecent: TLabel;
  15. lblSubPrecent: TLabel;
  16. private
  17. FHintProgress: Boolean;
  18. FHasSubProgress: Boolean;
  19. procedure InitForm;
  20. public
  21. constructor Create(AHintProgress, AHasSubProgress: Boolean);
  22. destructor Destroy; override;
  23. end;
  24. var
  25. ProgressHintForm: TProgressHintForm;
  26. procedure ShowProgressHint(const AHint: string; AMaxValue: Integer = 0;
  27. const ASubHint: string = ''; ASubMaxValue: Integer = 0);
  28. procedure UpdateProgressMaxValue(AMaxValue: Integer; AIsSub: Boolean = False);
  29. procedure UpdateProgressPosition(APos: Integer; ASubPos: Integer = 0); overload;
  30. procedure UpdateProgressPosition(AIsSub: Boolean = False); overload;
  31. procedure UpdateProgressHint(const AHint: string; AIsSub: Boolean = False); overload;
  32. procedure UpdateProgressHint(APos: Integer; AIsSub: Boolean = False); overload;
  33. procedure CloseProgressHint;
  34. implementation
  35. {$R *.dfm}
  36. procedure ShowProgressHint(const AHint: string; AMaxValue: Integer = 0;
  37. const ASubHint: string = ''; ASubMaxValue: Integer = 0);
  38. begin
  39. ProgressHintForm := TProgressHintForm.Create(AMaxValue <> 0, ASubMaxValue <> 0);
  40. ProgressHintForm.lblProgressHint.Caption := AHint;
  41. ProgressHintForm.gProgress.MaxValue := AMaxValue;
  42. ProgressHintForm.lblSubProgressHint.Caption := ASubHint;
  43. ProgressHintForm.gSubProgress.MaxValue := ASubMaxValue;
  44. ProgressHintForm.Show;
  45. end;
  46. procedure UpdateProgressMaxValue(AMaxValue: Integer; AIsSub: Boolean = False);
  47. begin
  48. if AIsSub then
  49. ProgressHintForm.gSubProgress.MaxValue := AMaxValue
  50. else
  51. ProgressHintForm.gProgress.MaxValue := aMaxValue;
  52. ProgressHintForm.Update;
  53. end;
  54. procedure UpdateProgressPosition(APos: Integer; ASubPos: Integer = 0);
  55. begin
  56. with ProgressHintForm do
  57. begin
  58. gSubProgress.Progress := ASubPos;
  59. lblSubPrecent.Caption := Format('%3d', [gSubProgress.PercentDone])+'%';
  60. gProgress.Progress := APos;
  61. lblPrecent.Caption := Format('%3d', [gProgress.PercentDone])+'%';
  62. Update;
  63. end;
  64. end;
  65. procedure UpdateProgressPosition(AIsSub: Boolean = False);
  66. begin
  67. with ProgressHintForm do
  68. begin
  69. if AIsSub then
  70. begin
  71. gSubProgress.Progress := Min(gSubProgress.Progress + 1, gSubProgress.MaxValue);
  72. lblSubPrecent.Caption := Format('%3d', [gSubProgress.PercentDone])+'%'
  73. end
  74. else
  75. begin
  76. gProgress.Progress := Min(gProgress.Progress + 1, gProgress.MaxValue);
  77. lblPrecent.Caption := Format('%3d', [gProgress.PercentDone])+'%';
  78. end;
  79. Update;
  80. end;
  81. end;
  82. procedure UpdateProgressHint(const AHint: string; AIsSub: Boolean = False);
  83. begin
  84. if AIsSub then
  85. ProgressHintForm.lblSubProgressHint.Caption := AHint
  86. else
  87. ProgressHintForm.lblProgressHint.Caption := AHint;
  88. ProgressHintForm.Update;
  89. end;
  90. procedure UpdateProgressHint(APos: Integer; AIsSub: Boolean = False);
  91. begin
  92. with ProgressHintForm do
  93. if AIsSub then
  94. begin
  95. gSubProgress.Progress := gSubProgress.Progress + APos;
  96. if gSubProgress.Progress > gSubProgress.MaxValue then
  97. gSubProgress.Progress := 0;
  98. lblSubPrecent.Caption := Format('%3d', [gSubProgress.PercentDone])+'%';
  99. end
  100. else
  101. begin
  102. gProgress.Progress := gProgress.Progress + APos;
  103. lblPrecent.Caption := Format('%3d', [gProgress.PercentDone])+'%';
  104. end;
  105. ProgressHintForm.Update;
  106. end;
  107. procedure CloseProgressHint;
  108. begin
  109. FreeAndNil(ProgressHintForm);
  110. end;
  111. { TProgressHintForm }
  112. constructor TProgressHintForm.Create(AHintProgress, AHasSubProgress: Boolean);
  113. begin
  114. inherited Create(nil);
  115. FHintProgress := AHintProgress;
  116. FHasSubProgress := AHasSubProgress;
  117. InitForm;
  118. end;
  119. destructor TProgressHintForm.Destroy;
  120. begin
  121. inherited;
  122. end;
  123. procedure TProgressHintForm.InitForm;
  124. begin
  125. if not FHintProgress then
  126. Height := 48
  127. else if FHasSubProgress then
  128. Height := 106
  129. else
  130. Height := 66;
  131. lblPrecent.Visible := FHintProgress;
  132. gProgress.Visible := FHintProgress;
  133. lblSubProgressHint.Visible := FHasSubProgress;
  134. lblSubPrecent.Visible := FHasSubProgress;
  135. gSubProgress.Visible := FHasSubProgress;
  136. end;
  137. end.