如何在这段代码中释放 TOleStream

发布于 2024-10-07 18:29:11 字数 1089 浏览 0 评论 0原文

这是来自 Delphi 中完成的自定义命名空间处理程序,我用它来将文件加载到 Web 浏览器组件中。

Datastream:IStream;

var
  F: TFileStream;
  Dummy: INT64;
begin

  F:=TFileStream.Create(strfilename fmOpenRead);
  CreateStreamOnHGlobal(0, True, DataStream);
  TOleStream.Create(DataStream).CopyFrom(F, F.Size);
  DataStream.Seek(0, STREAM_SEEK_SET, Dummy);
  TotalSize := F.Size;
  F.Free;
end;

问题是Fastmm4在程序结束时给出内存泄漏错误,并说TOleStream没有被释放。我如何释放它?如果我将 TOleStream 放入变量中并像这样分配,

var
TOS:TOleStream;

TOS:=TOleStream.Create(DataStream)
TOS.CopyFrom(F, F.Size);

..
TOS.Free;
End;

最后当我释放 TOS 变量时,我会收到错误(EAccessViolation 指向 ComObj 中的 TComObject.ObjRelease)。我将感谢您的意见和帮助。这个问题已经困扰我有一段时间了。

我还想知道它是否可能与 FastMM4 有关?会不会是提供了虚假信息?在如下代码中。 TOLEStream 通常如何释放?

f.SaveToStream(TOleStream.Create(DataStream));

有没有一种方法可以在不使用 TFileStream 的情况下将数据发送到数据流?

嗨,雷米, 您可以在此处找到带有 fastmm 的名称空间处理程序的工作演示项目以及问题过程: http://mode5 .webs.com/namespace.7z 加载项目时,单击按钮让命名空间处理程序加载文件。当你退出时,你应该得到 fastmm 错误。 亲切的问候,

This is from a custom namespacer handler done in Delphi I use to load files into a webbrowser component.


Datastream:IStream;

var
  F: TFileStream;
  Dummy: INT64;
begin

  F:=TFileStream.Create(strfilename fmOpenRead);
  CreateStreamOnHGlobal(0, True, DataStream);
  TOleStream.Create(DataStream).CopyFrom(F, F.Size);
  DataStream.Seek(0, STREAM_SEEK_SET, Dummy);
  TotalSize := F.Size;
  F.Free;
end;

The problem is that Fastmm4 gives a memory leak error when the program ends and says that TOleStream was not freed. How do I free it? If I put TOleStream in a variable and assign like this

var
TOS:TOleStream;

TOS:=TOleStream.Create(DataStream)
TOS.CopyFrom(F, F.Size);

..
TOS.Free;
End;

I get an error (EAccessViolation pointing to TComObject.ObjRelease in ComObj)in the end when I free the TOS variable. I would appreciate your comments and help. This problem has been bugging me for a while now.

I am also wondering if it could be something with FastMM4? Could it be giving false information? In a bit of code like the following. How is TOLEStream freed typically?

f.SaveToStream(TOleStream.Create(DataStream));

And is there a way to send data to datastream without using the TFileStream?

Hi Remy,
You can find a working demo project of the namespace handler with the fastmm and the problem procedure here: http://mode5.webs.com/namespace.7z
When the project loads, click the button to have the namespace handler load the files. When you exit, you should get the fastmm error.
Kind regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放手` 2024-10-14 18:29:11

如果您需要将 IStream 接口传递给某些内容,则应该查看 TStreamAdapter 对象,您可以在 TFileStream 上创建一个对象,并传递其 IStream 接口。

If you need to pass an IStream interface to something, you should look into the TStreamAdapter object, you can create one on the TFileStream, and pass its IStream interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文