Registriert seit: 10. Sep 2005
23 Beiträge
Delphi 6 Personal
|
Re: Transfer von Daten mit Pause bzw. Abbrech Button
6. Nov 2005, 14:01
Mein bisheriger Quellcode war:
Delphi-Quellcode:
uses ...jpeg,strutils;
// Screenshotprocedure /////////////////////////////////////////////////////
procedure ScreenShot(const Bitmap: TBitmap);
var
DesktopDC: HDC;
begin
DesktopDC := CreateDC('DISPLAY', nil, nil, nil);
try
Bitmap.PixelFormat := pfDevice;
Bitmap.Width := Screen.Width;
Bitmap.Height := Screen.Height;
BitBlt(Bitmap.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DesktopDC, 0, 0, SRCCOPY);
finally
DeleteDC(DesktopDC);
end;
end;
////////////////////////////////////////////////////////////////////////////
// Für den Client: /////////////////////////////////////////////////////////
var
Rec: Boolean=false;
rM: TMemoryStream;
rSize: Int64;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
rL : Integer;
Pic: TJpegimage;
begin
rL := Socket.ReceiveLength;
If rL = 0 then Exit;
If Rec then begin
Socket.ReceiveBuf(Pointer(Int64(rM.Memory) + rM.Position)^, rL);
rM.Position := rM.Position + rL;
ProgressBar1.Position:=round(rm.position/rsize*100);
If rM.Position = rSize then begin
ProgressBar1.Position:=100;
rM.Position := 0;
Pic := TJpegimage.Create;
try
Pic.LoadFromStream(rM);
Image1.Picture.Assign(Pic);
Image1.Refresh;
finally
Pic.Free;
end;
FreeAndNil(rM);
Rec := False;
end;
end
else begin
rSize := StrToInt(Socket.ReceiveText);
rM := TMemoryStream.Create;
rM.SetSize(rSize);
rM.Position := 0;
Rec := True;
Socket.SendText('ok');
end;
end;
// Ende der Clientprocedure ////////////////////////////////////////////////
// Für den Server: /////////////////////////////////////////////////////////
var
sM : TMemoryStream;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Bmp : TBitmap;
Jpeg : TJpegimage;
empfangen:string;
begin
empfangen:=socket.ReceiveText;
if leftstr(empfangen,length('Screenshot'))='Screenshot' then begin
FreeAndNil(sM);
Bmp:=TBitmap.Create;
Jpeg:=TJpegImage.Create;
sM:=TMemoryStream.Create;
try
ScreenShot(bmp);
Jpeg.CompressionQuality:=strtoint(rightstr(empfangen,length(empfangen)-length('Screenshot')));
Jpeg.Assign(Bmp);
Jpeg.SaveToStream(sM);
finally
Jpeg.Free;
Bmp.Free;
end;
Socket.SendText(IntToStr(sM.Size));
end;
// Empfänger hat Größe erhalten, das senden der Datei wird durchgeführt
If empfangen='ok' then begin
Socket.SendBuf(sM.Memory^, sM.Size); // genau diesen Vorgang will ich abbrechen können bzw. pausieren können
end;
end;
// Ende der Serverprocedure ///////////////////////////////////////////////////
// Screenshot anfordern
procedure TForm1.Button1Click(Sender: TObject);
begin
if ClientSocket1.Active then begin
ClientSocket1.Socket.SendText('Screenshot'+inttostr(scrollbar1.Position)); //Über die Scrollbar stell ich die Screenshot Qualität ein
end;
end;
@Net7
Das mit dem zerstückeln des Streams klingt gut, nur ich weiß nicht wie man einen Stream zerstückelt
|
|
Zitat
|