In Delphi XE2 I have a record type with the following structure :
TMachinInfoRec = record
IPStr: string[15];
Username: string[50];
Computername: string[100];
SentTime: TDateTime;
HasCommand: integer;
ClientCommands: array[0..9] of TMachineCommand;
end;
I define a variable on its and TMemoryStream variable on the Client side and send stream with TidTCPClient component:
var
MIRec: TMachinInfoRec;
msRecInfo: TMemoryStream;
begin
MIRec.IPStr = '192.168.100.101';
MIRec.Username := 'user-a';
MIRec.Computername := 'Computer-a';
MIRec.SentTime := Now();
idTCPClient.Host := '192.168.100.138';
idTCPClient.Port := 6000;
idTCPClient.Connect;
msRecInfo := TMemoryStream.Create;
msRecInfo.Write(msRecInfo, SizeOf(Client));
msRecInfo.Position := 0;
idTCPClient.IOHandler.Write(msRecInfo);
end;
and And get information on the server side with TidTCPServer :
procedure TFrmMainServer.TCPServerExecute(AContext: TIdContext);
var
MIRec: TMachinInfoRec;
msRecInfo: TMemoryStream;
begin
msRecInfo:= TMemoryStream.Create;
AContext.Connection.IOHandler.ReadStream(msRecInfo, SizeOf(MIRec));
msRecInfo.Read(msRecInfo, sizeOf(MIRec));
ShowMessage(MIRec.IPStr);
ShowMessage(MIRec.Computername)
end;
But a string that is displayed in this format:
MZ?.........yy..,.......@...................................,....
how can I solve this problem?
Shouldn't
msRecInfo.Write(msRecInfo, SizeOf(Client));
be
msRecInfo.Write(miRec, SizeOf(miRec));
Same for read:
msRecInfo.Read(miRec, sizeOf(MIRec));
Note that there are several other uncertain factors with this code:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With