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 my own and a TMemoryStream variable on the client side and send a stream with the 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 get server-side information using 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 the line displayed in this format:
MZ? ......... yy .., ....... @ ........................... ........, ....
How can I solve this problem?
source share