题
我想使用Delphi 2007将我的应用程序从Indy 9升级到10。现在不再编译了,因为找不到解码器。该代码使用粗体框架作为粗体。
有其他呼叫的替代方法吗?
更新 (我认为我简化了上一个示例太多)
原始代码:
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,所以这不是一个记忆。
解决方案
使用tiddecoder.decodebegin()是解码到tstream的正确方法。但是,您不需要中间的tidmemorystream(顺便说一句,现在已经在Indy 10中不存在很长一段时间 - 考虑升级到较新的版本)。您可以直接传递斑点流,例如:
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;
其他提示
是的,他们在9到10之间发生了很大的变化。
现在,我认为您有“解码复发器”,而不是解码器。因此,这样的事情应该做到:
var
DecodedBytes: TIdBytes;
begin
MIMEDecoder := TidDecoderMIME.Create(nil);
try
DecodedBytes := MIMEDecoder.DecodeBytes(vString);
vStream.Write(DecodedBytes[0], Length(DecodedBytes));
finally
FreeAndNil(MIMEDecoder);
end;
end;
不隶属于 StackOverflow