本文介绍了如何在这一段代码中释放TOleStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自Delphi中使用的自定义namespacer处理程序,用于将文件加载到Webbrowser组件中。

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;

问题是Fastmm4在程序结束时发出内存泄漏错误,并表示TOleStream未被释放。我该如何释放?如果我把TOleStream放在一个变量中,并且这样分配这个

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;

当我释放TOS变量时,我得到一个错误(EAccessViolation指向Comobj中的TComObject.ObjRelease)。感谢您的意见和帮助。这个问题现在已经在麻烦了一段时间。

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.

我也想知道是否可以使用FastMM4?可能会提供虚假信息吗?在一些代码如下所示。 TOLEStream如何释放?

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));

有没有办法在不使用TFileStream的情况下将数据发送到datastream?

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

Hi Remy,
您可以在这里找到具有fastmm和问题过程的命名空间处理程序的工作演示项目:
项目加载时,单击按钮使命名空间处理程序加载文件。退出时,应该得到fastmm错误。
亲爱的,

推荐答案

如果您需要将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.

这篇关于如何在这一段代码中释放TOleStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 19:48