【发布时间】:2016-03-17 11:27:58
【问题描述】:
我想使用 Indy IdTCPClient 和 IdTCPServer 将 TMemoStream 从 Android 发送到 Windows。
问题是这样的:
SizeOf(string) in Android is 4 bytes
SizeOf(string) in Windows 10 is 8 bytes
在android中我使用了这个代码:
type TMyRecord = record
x1: string;
x2: string;
end;
var
workRecord: TMyRecord;
rInfo: TMemoryStream;
begin
workRecord.x1:= 'Hello';
workRecord.x2:= 'How are you';
rInfo:= TMemoryStream.Create;
try
rInfo.Write(workRecord, SizeOf(workRecord)); //Size of workRecord is 8 bytes
AndroidTCPClient.IOHandler.Write(workRecord, 0, False);
finally
rInfo.Free;
end;
end;
在 Windows 10 中,我使用了以下代码:
type TMyRecord = record
x1: string;
x2: string;
end;
type TMyRecord = record
x1: string;
x2: string;
end;
var
workRecord: TMyRecord;
rInfo: TMemoryStream;
begin
rInfo:= TMemoryStream.Create;
try
AContext.Connection.IOHandler.ReadStream(rInfo, SizeOf(workRecord), False);
rInfo.Position:= 0;
rInfo.Read(workRecord, SizeOf(workRecord)); //Size of workRecord is 16 bytes
finally
rInfo.Free;
end;
end;
有人告诉我如何设置从Android到Windows的传输字符串吗?
【问题讨论】:
标签: android delphi indy10 delphi-10-seattle