unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdTCPConnection, IdTCPClient, IdBaseComponent, IdComponent,
IdTCPServer, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
server: TIdTCPServer;
client: TIdTCPClient;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure serverExecute(AThread: TIdPeerThread);
private
{ Private-Deklarationen }
procedure UpdateForm;
public
{ Public-Deklarationen }
end;
TTest=record
a,b,c:
String[50];
end;
var
Form1: TForm1;
Test, Test2: TTest;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
server.Active := true;
memo1.Lines[0] := '
';
end;
procedure TForm1.Button1Click(Sender: TObject);
Var Stream: TMemoryStream;
begin
client.Connect();
Test.a := '
a';
Test.b := '
b';
Test.c := '
c';
Stream := TMemoryStream.Create;
Stream.Position := 0;
Stream.
Write(Test,sizeof(Test));
Client.OpenWriteBuffer;
Client.WriteStream(Stream, True, True);
Client.CloseWriteBuffer;
Stream.Free;
end;
procedure TForm1.serverExecute(AThread: TIdPeerThread);
Var stream2: TMemorystream;
begin
label1.Caption := '
--';
Stream2 := TMemoryStream.Create;
Stream2.Clear;
Athread.Connection.ReadStream(Stream2, -1, true);
Stream2.Position := 0;
Stream2.ReadBuffer(test2, sizeOf(TTest));
AThread.Synchronize(UpdateForm);
Stream2.SaveToFile('
c:/streamtest.txt');
end;
procedure TForm1.UpdateForm;
begin
showmessage('
Ausgeführt!');
// wird nicht angezeigt
Label1.Caption := test2.b;
end;
end.