int dataSize = 1024;
unsigned char *data = (unsigned char*)malloc(4 * sizeof(unsigned char*));
memset(data, NULL, 4 * sizeof(unsigned char*));
*data = dataSize >> 24 & 0xff;
*(data + 1) = dataSize >> 16 & 0xff;
*(data + 2) = dataSize >> 8 & 0xff;
*(data + 3) = dataSize & 0xff;谢谢~
unsigned char *data = (unsigned char*)malloc(4 * sizeof(unsigned char*));
memset(data, NULL, 4 * sizeof(unsigned char*));
*data = dataSize >> 24 & 0xff;
*(data + 1) = dataSize >> 16 & 0xff;
*(data + 2) = dataSize >> 8 & 0xff;
*(data + 3) = dataSize & 0xff;谢谢~
dataSize : Integer;
data : array of PChar;
begin
dataSize := 1024;
SetLength(data,4);
FillChar(data, 0, 4);
data[0] := PChar(dataSize shr 24 and $ff);
data[1] := PChar(dataSize shr 16 and $ff);
data[2] := PChar(dataSize shr 8 and $ff);
data[3] := PChar(dataSize shr $ff);
end;
谢谢答复,不过貌似还是有问题。其实我是想吧一个integer型整数写到一个TMemoryStream的最前面,我看有C++代码是这么些的,我按你说的改造之后好像还是不行....
AThread.Connection.WriteInteger(strStream.Size);
AThread.Connection.WriteStream(strStream, True);我就是想把第一行WriteInteger给合并到创建strStream里面去。
stream : TMemoryStream;
i : integer;
begin
i := 1024;
stream := TMemoryStream.Create;
stream.Write(i,sizeof(Integer));
end;我这么写好像不对?
type
TTest = packed record
case Integer of
1:(data:Cardinal;) ;
2:(P:array [0..3] of Byte);
end;
var
Test:TTest;
begin
Test.data := 1024;
end;