unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls, System.Win.ScktComp,
Vcl.ComCtrls;
type
TForm1 =
class(TForm)
ClientSocket1: TClientSocket;
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
private
FStream : TFileStream;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
FThread =
class(TThread)
procedure Execute;
override;
end;
var
Form1: TForm1;
tpp : FThread;
implementation
{$R *.dfm}
procedure FThread.execute;
var
iLen: Integer;
RecLen: Integer;
Bfr: Pointer;
begin
iLen := form1.ClientSocket1.Socket.ReceiveLength;
GetMem(Bfr, iLen);
try
RecLen := form1.ClientSocket1.socket.ReceiveBuf(Bfr^, iLen);
form1.FStream.
Write(Bfr^, iLen);
form1.progressbar1.StepBy(iLen);
if form1.progressbar1.Position = form1.progressbar1.max
then
begin
form1.ClientSocket1.socket.Close;
form1.progressbar1.Position := 0;
form1.FStream.Free;
form1.Fstream :=
nil;
end;
finally
FreeMem(Bfr);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FStream := TFileStream.Create('
testdatei.dat', fmCreate
or fmShareDenyWrite);
clientsocket1.Open;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
tpp := FThread.Create(True);
tpp.FreeOnTerminate := false;
tpp.resume;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FStream :=
nil;
progressbar1.Max := 406776881;
//grösse der zu übermitelden datei wird dann später vom server empfangen.
end;
end.