Klar könnte ich die einzelnen Elemente per Schleife versenden. Aber ich hab halt nach einem einfach weg gesucht. Mein bisheriger Code:
Delphi-Quellcode:
type
TTest = record
s1, s2: string;
end;
TAoTest = array of TTest;
procedure TForm1.Button1Click(Sender: TObject);
var
Test: TAoTest;
begin
SetLength(Test, 5);
Test[3].s1 := 'Hallo';
with IdTCPClient1 do
begin
Connect;
try
WriteBuffer(Test[0], Length(Test));
finally
Disconnect;
end;
end;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
Test: TAoTest;
begin
with AThread.Connection do
try
SetLength(Test, 5);
ReadBuffer(Test[0], Length(Test));
// ReadBuffer(Test[0], 5);
// ReadBuffer(Test[0], SizeOf(Test));
ShowMessage(Test[3].s1);
finally
Disconnect;
end;
end;
In jedem der ReadBuffer-Fällen wird ist die MessageBox leer.
//edit:
Naja, so klappts wenigstens:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
Test: TAoTest;
i: integer;
begin
SetLength(Test, 5);
Test[3].s1 := 'Hallo';
with tc do
begin
Connect;
try
WriteLn(IntToStr(Length(test)));
for i := 0 to High(Test) do
WriteBuffer(Test[i], SizeOf(TTest));
finally
Disconnect;
end;
end;
end;
procedure TForm1.tsExecute(AThread: TIdPeerThread);
var
Test: TAoTest;
RText: string;
i: integer;
begin
with AThread.Connection do
try
RText := ReadLn;
SetLength(Test, StrToInt(RText));
for i := 0 to High(Test) do
ReadBuffer(Test[i], SizeOf(TTest));
ShowMessage(Test[3].s1);
finally
Disconnect;
end;
end;