我想用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但是我对我所有的变化都没有信心,因为我对印第不太了解。所以欢迎所有的评论。有一件事我不明白,那就是给CreateBlobStream打电话。我应该和FastMM核对一下,这样就不是备忘录泄露了。
发布于 2010-01-08 22:56:06
使用TIdDecoder.DecodeBegin()是对TStream进行解码的正确方法。然而,您不需要中间的TIdMemoryStream (它,BTW,已经很长时间没有在印第10 -考虑升级到一个较新的版本)。您可以直接传递Blob流,例如:
var
BlobElement : TBATypedBlob;
BlobStreamStr : String;
BlobStream : TStream;
MIMEDecoder : TidDecoderMIME;
begin
...
if BoldElement is TBATypedBlob then
begin
BlobElement := BoldElement as TBATypedBlob;
BlobStreamStr := Copy(ChangeValue, Pos(']',ChangeValue)+1, Maxint);
BlobElement.ContentType := Copy(ChangeValue, 2, Pos(']',ChangeValue)-2);
BlobStream := BlobElement.CreateBlobStream(bmWrite);
try
MIMEDecoder := TidDecoderMIME.Create(nil);
try
MIMEDecoder.DecodeBegin(BlobStream);
try
MIMEDecoder.Decode(BlobStreamStr);
finally
MIMEDecoder.DecodeEnd;
end;
finally
FreeAndNil(MIMEDecoder);
end;
finally
FreeAndNil(BlobStream);
end;
end;
...
end;发布于 2010-01-08 20:20:43
是的,在9点到10点之间有了很大的变化。
现在你用"DecodeBytes“代替了DecodeToStream,我想。所以像这样的事情应该可以做到:
var
DecodedBytes: TIdBytes;
begin
MIMEDecoder := TidDecoderMIME.Create(nil);
try
DecodedBytes := MIMEDecoder.DecodeBytes(vString);
vStream.Write(DecodedBytes[0], Length(DecodedBytes));
finally
FreeAndNil(MIMEDecoder);
end;
end;https://stackoverflow.com/questions/2028235
复制相似问题