ProgressHintFrm.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. unit ProgressHintFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, Gauges, StdCtrls, ExtCtrls;
  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);
  30. procedure UpdateProgressHint(const AHint: string; AIsSub: Boolean = False); overload;
  31. procedure UpdateProgressHint(APos: Integer; AIsSub: Boolean = False); overload;
  32. procedure CloseProgressHint;
  33. implementation
  34. {$R *.dfm}
  35. procedure ShowProgressHint(const AHint: string; AMaxValue: Integer = 0;
  36. const ASubHint: string = ''; ASubMaxValue: Integer = 0);
  37. begin
  38. ProgressHintForm := TProgressHintForm.Create(AMaxValue <> 0, ASubMaxValue <> 0);
  39. ProgressHintForm.lblProgressHint.Caption := AHint;
  40. ProgressHintForm.gProgress.MaxValue := AMaxValue;
  41. ProgressHintForm.lblSubProgressHint.Caption := ASubHint;
  42. ProgressHintForm.gSubProgress.MaxValue := ASubMaxValue;
  43. ProgressHintForm.Show;
  44. end;
  45. procedure UpdateProgressMaxValue(AMaxValue: Integer; AIsSub: Boolean = False);
  46. begin
  47. if AIsSub then
  48. ProgressHintForm.gSubProgress.MaxValue := AMaxValue
  49. else
  50. ProgressHintForm.gProgress.MaxValue := aMaxValue;
  51. ProgressHintForm.Update;
  52. end;
  53. procedure UpdateProgressPosition(APos: Integer; ASubPos: Integer = 0);
  54. begin
  55. with ProgressHintForm do
  56. begin
  57. gSubProgress.Progress := ASubPos;
  58. lblSubPrecent.Caption := Format('%3d', [gSubProgress.PercentDone])+'%';
  59. gProgress.Progress := APos;
  60. lblPrecent.Caption := Format('%3d', [gProgress.PercentDone])+'%';
  61. Update;
  62. end;
  63. end;
  64. procedure UpdateProgressHint(const AHint: string; AIsSub: Boolean = False);
  65. begin
  66. if AIsSub then
  67. ProgressHintForm.lblSubProgressHint.Caption := AHint
  68. else
  69. ProgressHintForm.lblProgressHint.Caption := AHint;
  70. ProgressHintForm.Update;
  71. end;
  72. procedure UpdateProgressHint(APos: Integer; AIsSub: Boolean = False);
  73. begin
  74. with ProgressHintForm do
  75. if AIsSub then
  76. begin
  77. gSubProgress.Progress := gSubProgress.Progress + APos;
  78. if gSubProgress.Progress > gSubProgress.MaxValue then
  79. gSubProgress.Progress := 0;
  80. lblSubPrecent.Caption := Format('%3d', [gSubProgress.PercentDone])+'%';
  81. end
  82. else
  83. begin
  84. gProgress.Progress := gProgress.Progress + APos;
  85. lblPrecent.Caption := Format('%3d', [gProgress.PercentDone])+'%';
  86. end;
  87. ProgressHintForm.Update;
  88. end;
  89. procedure CloseProgressHint;
  90. begin
  91. FreeAndNil(ProgressHintForm);
  92. end;
  93. { TProgressHintForm }
  94. constructor TProgressHintForm.Create(AHintProgress, AHasSubProgress: Boolean);
  95. begin
  96. inherited Create(nil);
  97. FHintProgress := AHintProgress;
  98. FHasSubProgress := AHasSubProgress;
  99. InitForm;
  100. end;
  101. destructor TProgressHintForm.Destroy;
  102. begin
  103. inherited;
  104. end;
  105. procedure TProgressHintForm.InitForm;
  106. begin
  107. if not FHintProgress then
  108. Height := 48
  109. else if FHasSubProgress then
  110. Height := 106
  111. else
  112. Height := 66;
  113. lblPrecent.Visible := FHintProgress;
  114. gProgress.Visible := FHintProgress;
  115. lblSubProgressHint.Visible := FHasSubProgress;
  116. lblSubPrecent.Visible := FHasSubProgress;
  117. gSubProgress.Visible := FHasSubProgress;
  118. end;
  119. end.