Indy10 中的 DecodeToStream
我想使用 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。所以欢迎所有评论。我不明白的一件事是对 CreateBlobStream 的调用。我应该向 FastMM 核实一下,这样就不会出现内存泄漏。
I want to upgrade my application from Indy 9 to 10 with Delphi 2007.
Now this don't compile anymore as DecodeToStream is not found.
The code use Bold framwork as there is reference to BoldElement.
Any alternative methods to call ?
UPDATE (I think I simplify previous example too much)
Original code:
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
After my change:
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
But I'm not confident at all of my changes as I don't know Indy so much. So all comments are welcome. One thing I don't understand is the call to CreateBlobStream. I should check with FastMM so it isn't a memleak.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 TIdDecoder.DecodeBegin() 是解码为 TStream 的正确方法。但是,您不需要中间的 TIdMemoryStream(顺便说一句,它在 Indy 10 中已经很长时间不存在了 - 考虑升级到更新的版本)。您可以直接传递 Blob 流,例如:
Using TIdDecoder.DecodeBegin() is the correct way to decode to a TStream. However, you do not need the intermediate TIdMemoryStream (which, BTW, has not existed in Indy 10 for a long time now - consider upgrading to a newer release). You can pass the Blob stream directly instead, for example:
是的,他们在 9 到 10 之间改变了很多。
我认为现在你有“DecodeBytes”而不是 DecodeToStream。所以像这样的事情应该做到:
Yes they changed a lot between 9 and 10.
Now you have "DecodeBytes" instead of DecodeToStream I think. So something like this should do it: