【发布时间】:2011-01-02 22:46:46
【问题描述】:
我想使用 Delphi 2007 将我的应用程序从 Indy 9 升级到 10。 现在这不再编译了,因为没有找到 DecodeToStream。 代码使用 Bold 框架,因为有对 BoldElement 的引用。
还有其他调用方法吗?
更新(我觉得我把前面的例子简化得太多了)
原码:
BlobStreamStr : String;
MIMEDecoder : TidDecoderMIME;
if (BoldElement is TBATypedBlob) then
begin
BlobStreamStr := copy(ChangeValue,pos(']',ChangeValue)+1,maxint);
(BoldElement as TBATypedBlob).ContentType := copy(ChangeValue,2,pos(']',ChangeValue)-2);
MIMEDecoder := TidDecoderMIME.Create(nil);
try
MIMEDecoder.DecodeToStream(BlobStreamStr,(BoldElement as TBATypedBlob).CreateBlobStream(bmWrite));
finally
FreeAndNil(MIMEDecoder);
end;
end
更改后:
BlobStreamStr : String;
MIMEDecoder : TidDecoderMIME;
LStream : TIdMemoryStream;
if (BoldElement is TBATypedBlob) then
begin
BlobStreamStr := copy(ChangeValue, pos(']', ChangeValue) + 1, maxint);
(BoldElement as TBATypedBlob).ContentType := copy(ChangeValue, 2, pos(']',ChangeValue)-2);
MIMEDecoder := TidDecoderMIME.Create(nil);
LStream := TIdMemoryStream.Create;
try
MIMEDecoder.DecodeBegin(LStream);
MIMEDecoder.Decode(BlobStreamStr, 0, Length(BlobStreamStr));
LStream.Position := 0;
ReadTIdBytesFromStream(LStream, DecodedBytes, Length(BlobStreamStr));
// Should memory for this stream be released ??
(BoldElement as TBATypedBlob).CreateBlobStream(bmWrite).Write(DecodedBytes[0], Length(DecodedBytes));
finally
MIMEDecoder.DecodeEnd;
FreeAndNil(LStream);
FreeAndNil(MIMEDecoder);
end;
end
但我对自己的所有变化都没有信心,因为我对 Indy 了解不多。所以欢迎所有的cmets。我不明白的一件事是对 CreateBlobStream 的调用。我应该与 FastMM 核对一下,这样它就不是内存泄漏了。
【问题讨论】:
-
是的,对 CreateBlobStream() 的调用是内存泄漏。使用完毕后,您需要 Free() 流。