문제

Delphi 2007로 INDY 9에서 10으로 응용 프로그램을 업그레이드하고 싶습니다. 이제 DecodetoStream을 찾을 수 없으므로 더 이상 컴파일하지 않습니다. 코드는 굵게에 대한 참조가 있으므로 Bold Framwork를 사용합니다.

전화 할 대체 방법이 있습니까?

업데이트 (이전 예제를 너무 단순화하는 것 같아요)

원본 코드 :

    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

그러나 나는 인디를 너무 많이 모르기 때문에 나의 모든 변화에 대해 확신하지 못한다. 따라서 모든 의견을 환영합니다. 내가 이해하지 못하는 한 가지는 BlobStream을 CreatebloBStream을 작성하는 것입니다. Fastmm으로 확인해야합니다.

도움이 되었습니까?

해결책

tiddecoder.decodebegin ()을 사용하는 것이 tstream으로 디코딩하는 올바른 방법입니다. 그러나 중간 TidMemoryStream이 필요하지 않습니다 (BTW는 현재 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;

다른 팁

예, 그들은 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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top