我正在使用2010年最后一次修改的Russell Libby Pipes。我有一个TpServer发送/接收带有多个TpClients的消息。这在Delphi7下运行良好,但现在在XE(最近将Pipes升级到2010)中,字符串之间的字符串为#0。 '9' #0'8 '#0'。我怀疑Unicode是问题,但解决方案已经避开了我。这是我的服务器发送和客户端接收例程。任何帮助表示赞赏。
procedure TfrmServer.CommSend(aStr: String);
begin // Broadcast message; Messages are kept as short as possible
editSend.Text := aStr;
try
Size := editSend.GetTextBuf(Buffer, 250); // Put text into buffer
PipeServer.Broadcast(Buffer^, Size*2); // Send the message to the Clients
Application.ProcessMessages;
except
end;
end;
PROCEDURE TfrmClient.PipeMessage(Sender: TObject; Pipe: Cardinal; Stream: TStream);
VAR // Incoming message
xInStream: TStringStream;
xSize: Integer;
BEGIN // Message received from network
xInStream := TStringStream.Create('');
TRY
xSize := Stream.Size;
xInStream.CopyFrom(Stream, xSize); // Copy stream to local variable
editRcvd.Text := xInStream.DataString;
frmOptions.NetMessage(editRcvd.Text);
EXCEPT
ShowMessage('DMS Client - Message Error: ' + editRcvd.Text); // Debug
END;
xInStream.Free; // Erases any contents
END;