unit UProgressHandler;
interface
type
IProgressHandler =
Interface(IIinterface)
['
{...}']
procedure ProgressStart;
procedure Progress(AProzent: Integer;
var IsAbort: Boolean);
procedure ProgressEnd;
End;
implementation
end.
unit UDateiOperationen;
interface
procedure KopiereDatei(
const AQuelle, AZiel:
string;
const AProgressHandler: IProgressHandler);
implementation
procedure KopiereDatei(
const AQuelle, AZiel:
string;
const AProgressHandler: IProgressHandler);
begin
AProgressHandler.ProgressStart;
try
for {... irgendeine Schleife}
begin
{tu irgenwas}
IsAbort := False;
AProgressHandler.Progress(xProzent, IsAbort);
if IsAbort
then
Exit;
end;
finally
AProgressHandler.ProgressEnd;
end;
end;
end.
unit UForm1;
interface
type
TForm1 =
class(TForm, IProgressHandler)
FAborted: Boolean;
procedure ButtonDateiKopierenClick(Sender: TObject);
procedure ButtonAbortClick(Sender: TObject);
{IProgressHandler}
procedure ProgressStart;
procedure Progress(AProzent: Integer;
var IsAbort: Boolean);
procedure ProgressEnd;
end
implementation
procedure TForm1.ButtonDateiKopierenClick(Sender: TObject);
begin
ButtonDateiKopieren.Enabled := False;
ButtonAbort.Enabled := True;
FAborted := False;
try
KopiereDatei(EditQuelle.Text, EditZiel.Text, Self);
finally
ButtonDateiKopieren.Enabled := True;
ButtonAbort.Enabled := False;
end;
end;
procedure TForm1.ButtonAbortClick(Sender: TObject);
begin
FAborted := True;
ButtonAbort.Enabled := False;
end;
procedure TForm1.ProgressStart;
begin
FProgressBar1.Visible := True;
FProgressBar1.Position := 0;
end;
procedure TForm1.Progress(AProzent: Integer;
var IsAbort: Boolean);
begin
FProgressBar1.Position := AProzent;
IsAborted := FAborted;
end;
procedure TForm1.ProgressEnd;
begin
FProgressBar1.Visible := False;
end;