1

Delphi2007を使用してアプリケーションをIndy9から10にアップグレードしたいのですが、DecodeToStreamが見つからないため、これはコンパイルされなくなりました。BoldElementへの参照があるため、コードはBoldフレームワークを使用します。

呼び出す代替メソッドはありますか?

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

しかし、私はインディをあまり知らないので、私の変更のすべてに自信がありません。したがって、すべてのコメントを歓迎します。私が理解していないことの1つは、CreateBlobStreamの呼び出しです。メモリリークにならないように、FastMMで確認する必要があります。

4

2 に答える 2

2

はい、9から10の間で大きく変化しました。

これで、DecodeToStreamの代わりに「DecodeBytes」ができたと思います。したがって、このようなものがそれを行う必要があります:

var
  DecodedBytes: TIdBytes;
begin
  MIMEDecoder := TidDecoderMIME.Create(nil);
  try
    DecodedBytes := MIMEDecoder.DecodeBytes(vString);
    vStream.Write(DecodedBytes[0], Length(DecodedBytes));
  finally
    FreeAndNil(MIMEDecoder);
  end;
end;
于 2010-01-08T20:20:43.223 に答える
2

TIdDecoder.DecodeBegin()を使用することは、TStreamにデコードする正しい方法です。ただし、中間のTIdMemoryStreamは必要ありません(ところで、Indy 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-08T22:56:06.520 に答える