1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| unit uMultiProgressBar;
interface
uses
Classes, Forms, Controls, ComCtrls;
type
TMultiProgressBarForm = class(TForm)
private
FBarCount: Integer;
function GetBars(const Index: Integer): TProgressBar;
function GetBarCount(): Integer;
function GetMax(const Index: Integer): Integer;
procedure SetMax(const Index, Value: Integer);
function GetPosition(const Index: Integer): Integer;
procedure SetPosition(const Index, Value: Integer);
protected
property Bars[const Index: Integer]: TProgressBar read GetBars;
public
constructor Create(AOwner: TComponent; BarCount: Integer); reintroduce;
procedure StepBy(const Index: Integer; Delta: Integer = 1);
property Max[const Index: Integer]: Integer read GetMax write SetMax;
property Position[const Index: Integer]: Integer read GetPosition write SetPosition;
property BarCount: Integer read GetBarCount;
end;
implementation
constructor TMultiProgressBarForm.Create(AOwner: TComponent; BarCount: Integer);
var
I: Integer;
ProgressBar: TProgressBar;
begin
inherited CreateNew(AOwner); // Pas de DFM
FBarCount := BarCount;
if FBarCount > 0 then
begin
Width := Screen.WorkAreaWidth div 2;
for I := 0 to BarCount - 1 do
begin
ProgressBar := TProgressBar.Create(Self);
ProgressBar.Parent := Self;
ProgressBar.Align := alTop;
ProgressBar.Tag := I;
ProgressBar.Max := 100;
ProgressBar.Smooth := True;
end;
BorderStyle := bsToolWindow;
inherited Position := poScreenCenter;
FormStyle := fsStayOnTop;
Enabled := False;
AutoSize := True;
Show();
BringToFront();
end;
end;
procedure TMultiProgressBarForm.StepBy(const Index: Integer; Delta: Integer = 1);
begin
if Index < FBarCount then
Bars[Index].StepBy(Delta);
end;
function TMultiProgressBarForm.GetBars(const Index: Integer): TProgressBar;
var
I: Integer;
begin
if Index < FBarCount then
begin
for I := 0 to ComponentCount - 1 do
begin
if (Components[I] is TProgressBar) and (TProgressBar(Components[I]).Tag = Index) then
begin
Result := TProgressBar(Components[I]);
Exit;
end;
end;
end;
Result := nil;
end;
function TMultiProgressBarForm.GetBarCount(): Integer;
begin
Result := FBarCount;
end;
function TMultiProgressBarForm.GetMax(const Index: Integer): Integer;
begin
if Index < FBarCount then
Result := Bars[Index].Max
else
Result := 0;
end;
procedure TMultiProgressBarForm.SetMax(const Index, Value: Integer);
begin
if Index < FBarCount then
with Bars[Index] do
begin
Max := Value;
Position := 0;
end;
end;
function TMultiProgressBarForm.GetPosition(const Index: Integer): Integer;
begin
if Index < FBarCount then
Result := Bars[Index].Position
else
Result := 0;
end;
procedure TMultiProgressBarForm.SetPosition(const Index, Value: Integer);
begin
if Index < FBarCount then
begin
Bars[Index].Position := Value;
end;
end;
end. |
Partager