Re: Cannot convert 'TFileStream *' to 'TMetaClass *' while encoding and decoding

Giganews Newsgroups
Subject: Re: Cannot convert 'TFileStream *' to 'TMetaClass *' while encoding and decoding
Posted by:  Remy Lebeau (TeamB) (
Date: Wed, 8 Sep 2004

"julien moorrees" <n…> wrote in message

> I am using TIdDecoderMIME and TIdEncoderMIME from Indy 9.00.16 to encode
> and decode files.

This is not an HTTP issue.  This is not the correct newsgroup for such
issues.  The "coders" newsgroup would have been more appropriate.

> AnsiString TMessageCenter::getXMLDataForFile(int aFileID,
> int aFilePart,int aMaxBytes) {
>    AnsiString tTransmit = "";
> TFileStream *tInFile;
> tInFile=new TFileStream( AnsiString("test.txt"),fmOpenRead |
> fmShareDenyNone);
>    long tOffset = aMaxBytes * aFilePart;
>    long newOff =  tInFile->Seek(tOffset,soFromBeginning );
> tTransmit = EncoderMIME->Encode(tInFile,aMaxBytes-1);
> return tTransmit;
> }

That code has a memory leak in it.  You are never freeing the TFileStream

> bool TIMManager::writeEncodedstringToFile(int aFileID,int aFilePart,int
> aMaxBytes, AnsiString aEncodedstring) {
> TFileStream *tOutFile;
> tOutFile=new TFileStream( AnsiString("output.txt"),fmOpenWrite |
> fmShareDenyNone);
>    long tOffset = aMaxBytes * aFilePart;
>    long newOff =  tOutFile->Seek(tOffset,soFromBeginning );
> //Save to disk
>    DecoderMIME->DecodeString(tOutFile,aEncodedstring);
>    return true;
> }

What exactly is this code supposed to be doing?  Are you really trying to
decode an encoded string and store the resulting unencoded data to a stream?
If so, then you should be using DecodeToStream() instead of DecodeString():

    DecoderMIME->DecodeToStream(aEncodedstring, tOutFile);

There is no version of DecodeString() with the parameters that you are
trying to pass to it.

If, on the other hand, you do not mean to decode the encoded data, but just
store the encoded data as-is, then why are you trying to decode it at all?
Just write the encoded string as-is:

    tOutFile->Write(aEncodedstring.c_str(), aEncodedstring.Length());

> Cannot convert 'TFileStream *' to 'TMetaClass *'

If you look in IdCoder.hpp, where DecodeString() is declared, you will see
that it has an extra parameter that you are not specifying.  DecodeString()
is declared as a "class" method in the original Delphi code.  Class methods
are Delphi's equivilent (but not exactly the same) to C++ static methods.
The TMetaClass parameter is C++'s way of maintaining compatibility with the
Delphi environment.




In response to

Cannot convert 'TFileStream *' to 'TMetaClass *' while encoding and decoding wit posted by julien moorrees on Thu, 09 Sep 2004