Einzelnen Beitrag anzeigen

Benni0811

Registriert seit: 26. Sep 2016
25 Beiträge
 
Delphi 10.1 Berlin Starter
 
#12

AW: Über Indy versandte Dateien lassen sich nicht öffnen

  Alt 30. Mär 2017, 12:58
Mein Projekt:
Delphi-Quellcode:
unit Server;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdStreamvcl, IdTCPServer, idcontext;

type
  TForm1 = class(TForm)
    IdTCPServer1: TIdTCPServer;
    procedure FormCreate(Sender: TObject);
    procedure IdTCPServer1Execute(AContext: TIdContext);
  private

  public

  end;

const
  filename='h:\Test.bmp';

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
    IdTCPServer1.Active:=true;
end;

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
Var
  FStream: TFileStream;
begin
    FStream := TFileStream.Create(filename, fmCreate);
    FStream.Position := 0;
    AContext.Connection.Socket.ReadStream(fstream);
    AContext.Connection.Disconnect;
    FStream.Destroy;
end;

end.
Delphi-Quellcode:
unit Client;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer,
  StdCtrls, IdTCPConnection, IdTCPClient;

type
  TForm2 = class(TForm)
    Button1: TButton;
    IdTCPClient1: TIdTCPClient;
    procedure Button1Click(Sender: TObject);
  private
  
  public

  end;
  
const
  filename='c:\test.bmp';

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
Var FStream:TFileStream;
begin
    FStream := TFileStream.Create(filename, fmOpenRead);
    IdTcpClient1.Connect;
    IdTcpClient1.Socket.Write(FStream);
    IdTcpClient1.Disconnect;
    FStream.Destroy;
end;

end.
Funktioniert auch ohne with nicht
  Mit Zitat antworten Zitat