如何将TMemoryStream清空

gloom 2002-04-09 05:25:16
我想利用一个TMemoryStream不断地从一个文件中获得数据,可是我如何将前一进的数据 啊?我用下面的代码老出错啊

void __fastcall TForm1::FileSocketClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString rev=Socket->ReceiveText();
int pos=rev.Pos("%%");
if (rev.SubString(1,pos-1)=="get")
{
rev.Delete(1,pos+1);
pos=rev.Pos("%%");
int user=rev.SubString(1,pos-1).ToInt();
AnsiString fName=ExtractFilePath(Application->ExeName)+"server"+IntToStr(user)+".huc";
//if (mStream!=NULL) delete mStream; mStream->Clear();
//mStream->Free();

//mStream=new TMemoryStream();
mStream->LoadFromFile(fName);
Socket->SendStream(mStream);
}
}
...全文
246 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gloom 2002-04-10
  • 打赏
  • 举报
回复
因为我是在Socket事件中处理的,而Socket一次只能发送8K字节,而我的流有将近1MB,所以它必须分成多次来发送,这个流是不是被它保护起来了?
gloom 2002-04-10
  • 打赏
  • 举报
回复
不行啊,版主。我一用Clear就出现异常,
Access violation at address 00000001.Read of address 00000001.
第一次正常,第二次便 出现此异常。
猛禽 2002-04-09
  • 打赏
  • 举报
回复
如春阳兄所言,用Clear即可
Wingsun 2002-04-09
  • 打赏
  • 举报
回复
不需要Free和delete,这样才可以重复使用。
Wingsun 2002-04-09
  • 打赏
  • 举报
回复
TMemoryStream::Clear

Frees the memory buffer, discarding all data associated with the memory stream.

void __fastcall Clear(void);

Description

Use Clear to empty the memory buffer for the memory stream and free all associated memory. In addition to freeing the memory associated with the memory buffer, Clear

Sets the Memory property to NULL.
Sets the Position property to 0.
Sets the Size property to 0.

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧