我想用Delphi 2007将我的应用程序从Indy 9升级到10。 现在,由于找不到DecodeToStream,因此无法编译。 代码使用粗体框架,因为有对BoldElement的引用。Indy10中的DecodeToStream
任何其他方法调用?
UPDATE(我想我简化前面的例子太多了)
原始代码:
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,所以我的变化。所以所有的意见都欢迎。有一件事我不明白是对CreateBlobStream的调用。我应该检查FastMM,所以它不是一个memleak。
是的,对CreateBlobStream()的调用是内存泄漏。当您完成使用时,您需要释放()流。 – 2010-01-08 22:47:00