Endlich hab ichs mit Fortschrittsanzeige!
Delphi-Quellcode:
// Client
{Global} var Groesse : Integer;
procedure TSendeForm.DateiSendeButtonClick(Sender : TObject);
var FStream : TFileStream;
IDS : TidStreamVCL;
begin
TCPSender.Host := HostEdit.text;
if not (DateiOpenDialog.execute) then
exit;
FStream := TFileStream.Create(DateiOpenDialog.FileName, fmOpenRead);
IDS := TidStreamVCL.Create(FStream);
with TCPSender do
begin
Connect;
try
Socket.Write(IDS, 0, true);
finally
Disconnect;
end;
end;
FStream.Free;
IDS.Free;
end;
procedure TSendeForm.TCPSenderWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer);
begin
ProgressBar.Position := Round((AWorkCount / Groesse) * 100);
Application.ProcessMessages;
end;
procedure TSendeForm.TCPSenderWorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Integer);
begin
Groesse := AWorkCountMax;
end;
// Server
procedure TEmpfangsForm.TCPReceiverExecute(AContext: TIdContext);
var FSTream : TFileStream;
SizeOfIncomingStream : Integer;
IDS : TidStreamVCL;
begin
if not (DateiSaveDialog.execute) then
begin
showmessage('Es wurde keine Datei ausgewählt!');
exit;
end;
FStream := TFileStream.Create(DateiSaveDialog.FileName, fmCreate);
IDS := TidStreamVCL.Create(FStream);
with AContext.connection do
begin
try
SizeOfIncomingStream := Socket.ReadInteger;
Socket.ReadStream(IDS, SizeOfIncomingStream);
finally
Disconnect;
end;
end;
IDS.VCLStream.Position := 0;
FStream.Free;
IDS.Free;
end;