Delphi 10: Problems with SizeOf(string) - Windows vs Android -
i want send tmemostream android windows using indy idtcpclient , idtcpserver.
the problem this:
sizeof(string) in android 4 bytes sizeof(string) in windows 10 8 bytes
in android used code:
type tmyrecord = record x1: string; x2: string; end; var workrecord: tmyrecord; rinfo: tmemorystream; begin workrecord.x1:= 'hello'; workrecord.x2:= 'how you'; rinfo:= tmemorystream.create; try rinfo.write(workrecord, sizeof(workrecord)); //size of workrecord 8 bytes androidtcpclient.iohandler.write(workrecord, 0, false); rinfo.free; end; end;
in windows 10 used code:
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 16 bytes rinfo.free; end; end;
anyone advise me how set transmission string android windows?
sizeof(string)
size of pointer. windows program compiled 64 bit , pointers 8 bytes wide. android program targets 32 bit , pointers 4 bytes wide.
the bigger problem cannot expect send pointers 1 process another. pointers refer memory in sending program. have no meaning in recipient. should serialize data, instance json, , send that. recipient can deserialize upon receipt.
Comments
Post a Comment