如何分解流数据???(50分)

  • 主题发起人 主题发起人 新小丸子
  • 开始时间 开始时间

新小丸子

Unregistered / Unconfirmed
GUEST, unregistred user!
写入流数据如下:
var
s:string;
m:tmemorystream;
thepos:integer;
.....
m:=TMemorystream.create;
m.position:=0;
while not query1.eof do
begin
thepos:=m.size;
s:=Format('%8d%10s',[query1.Fields[0].Value.AsInteger,
query1.Fields[1].Value.AsString]);
s.savetostream(m);[red]//这行报错是:record,object or class type required[/red]
s.savetostream('#13#10');[red]//报错同上[/red]
m.position:=thepos+length(s)+1;
query1.next;
end;
socket.sendtext(inttostr(m.size));
接收流如下:
var
buffer:array [0..10000] of byte;
len:integer;
scontent,stitle:string;
N37: TMenuItem;
m:tmemorystream;
..................
len:=socket.ReceiveLength;
socket.ReceiveBuf(buffer,len);
m.Write(buffer,len);
m.Position:=0;
try
scontent.LoadFromStream(m);[red]//这行报错是:record,object or class type required
//此处分解出id和title来赋给sid,stitle[/red]
N37:= TMenuItem.Create(MainMenu1);
N37.Caption := stitle;
N37.OnClick := myClick(N23);
MainMenu1.Items.Add(N37);
finally
clientsocket1.Active:=false;
clientsocket1.Active:=true;
m.Clear;
c:=0;
end;
end;

红色的地方,请各位高手能帮帮我么?[:)]
 
string;类型不能savetostream,必须是类,记录或对象才可以用这个函数
 
var
Len: Integer;
RecBuf:array of char;
begin
Len:=Socket.ReceiveLength;
SetLength(RecBuf, Len);
Socket.ReceiveBuf(RecBuf, Len);
{上一句出错,如果在定义时用: RecBuf:array[1..2048] of char;(静态数组,
并隐藏:SetLength(RecBuf, Len);)则可以,请问这是为什么??}
...
end;
 
后退
顶部