BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ObjectResourceToText

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Kenneth de Camargo
Guest





PostPosted: Tue Feb 28, 2006 12:03 am    Post subject: ObjectResourceToText Reply with quote



Hello all,

I had code using ObjectResourceToText that managed to translate binary
..dfm files into text files; now (with BCB2006) it no longer works, does
anyone know what could be happening and (more important) if there's a
workaround?

--
Ken
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Feb 28, 2006 2:03 am    Post subject: Re: ObjectResourceToText Reply with quote



"Kenneth de Camargo" <INVERT:rb.moc.arret@jcrk> wrote in message
news:xn0eizlwu2fciu000 (AT) forums (DOT) borland.com...

Quote:
I had code using ObjectResourceToText that managed to translate
binary .dfm files into text files; now (with BCB2006) it no longer works

Just saying that it does not work says nothing about the actual problem that
is occuring. Always provide specific details. What does your code look
like? Is the parsing simply returning different data than you expect? Is
an exception being thrown?


Gambit
Back to top
Kenneth de Camargo
Guest





PostPosted: Tue Feb 28, 2006 2:03 am    Post subject: Re: ObjectResourceToText Reply with quote



Remy Lebeau (TeamB) wrote:

Quote:

"Kenneth de Camargo" <INVERT:rb.moc.arret@jcrk> wrote in message
news:xn0eizlwu2fciu000 (AT) forums (DOT) borland.com...

I had code using ObjectResourceToText that managed to translate
binary .dfm files into text files; now (with BCB2006) it no longer
works

Just saying that it does not work says nothing about the actual
problem that is occuring. Always provide specific details. What
does your code look like? Is the parsing simply returning different
data than you expect? Is an exception being thrown?

An error message stating that it is not the adequate format is shown
and an exception is thrown.

The code is simply ObjectResourcetoText(in, out) where in is a
TFileStream and out is a TMemoryStream.

The .dfm file is a legit ninary format form, the IDE opens it without
any problems.

--
Ken
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Feb 28, 2006 4:03 am    Post subject: Re: ObjectResourceToText Reply with quote

"Kenneth de Camargo" <INVERT:rb.moc.arret@jcrk> wrote in message
news:xn0eizokc2qyw5000 (AT) forums (DOT) borland.com...

Quote:
An error message stating that it is not the adequate format is
shown and an exception is thrown.

Please always quote the error text exactly as it is shown to you.

Since you did not show your code yet, I can only guess that you are trying
to load something that is not actually a DFM, or is maybe a DFM for an older
version of the VCL.

Quote:
The code is simply ObjectResourcetoText(in, out) where in is
a TFileStream and out is a TMemoryStream.

But that doesn't show where you are actually loading the input DMF from
specifically.

Quote:
The .dfm file is a legit ninary format form, the IDE opens it
without any problems.

The IDE does not store or load DFMs from individual files. They are stored
as resources in the project's main .exe file.

Besides, even if the IDE can load it fine, then all the more reason to think
that ObjectResourceToText() itself works fine (especially since the VCL uses
it internally), and that you may not be using it properly in your own code.


Gambit
Back to top
Kenneth de Camargo
Guest





PostPosted: Tue Feb 28, 2006 7:03 pm    Post subject: Re: ObjectResourceToText Reply with quote

Remy Lebeau (TeamB) wrote:

Quote:
An error message stating that it is not the adequate format is
shown and an exception is thrown.

Please always quote the error text exactly as it is shown to you.

"Project HW.exe raised exception class EReadError with message 'Invalid
stream format'." (while debugging)

Quote:
Since you did not show your code yet, I can only guess that you are
trying to load something that is not actually a DFM, or is maybe a
DFM for an older version of the VCL.

I explicitly said it was a DFM for an older version of the VCL.
The whole code follows (DFMFilename is an AnsiString with the name of
the form):

TMemoryStream *fs = new TMemoryStream();
TFileStream *in = new TFileStream(DFMFilename, fmOpenRead);
char tmpbuff[7];
in->Read(tmpbuff, 6);
tmpbuff[6] = '\0';
String test = tmpbuff;
if (test == "object")
fs->LoadFromStream(in);
else
try {
ObjectBinaryToText(in, fs);
} catch (...) {
delete fs;
MessageDlg("Error parsing dfm file (invalid format).", mtWarning,
TMsgDlgButtons() << mbOK, 0);
}

Quote:
The code is simply ObjectResourcetoText(in, out) where in is
a TFileStream and out is a TMemoryStream.

But that doesn't show where you are actually loading the input DMF
from specifically.

See above.

Quote:
The .dfm file is a legit ninary format form, the IDE opens it
without any problems.

The IDE does not store or load DFMs from individual files. They are
stored as resources in the project's main .exe file.

Not in this case. It is a source only project, and yet the IDE loads it
without a problem.

Quote:
Besides, even if the IDE can load it fine, then all the more reason
to think that ObjectResourceToText() itself works fine (especially
since the VCL uses it internally), and that you may not be using it
properly in your own code.


Gambit

Hence my puzzlement, considering that this is code that worked
perfectly (still does) with BCB 6.

--
Ken
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Feb 28, 2006 10:03 pm    Post subject: Re: ObjectResourceToText Reply with quote

"Kenneth de Camargo" <INVERT:rb.moc.arret@jcrk> wrote in message
news:xn0ej0rw43xhbd000 (AT) forums (DOT) borland.com...

Quote:
I explicitly said it was a DFM for an older version of the VCL.

No, you did not. All you said was that you were loading .dfm files. You
never said anything about their versions.

Quote:
this is code that worked perfectly (still does) with BCB 6.

Actually, it does not work. I ran your code as-is under BCB 6 and it fails
every time on binary DFM files.

You are reading the first 6 bytes of the DFM file, but you are not leaving
the file stream in the corrent Position before passing it to
ObjectBinaryToText(). In a binary .dfm file,. there is an extra binary
header at the beginning of the file before the DFM data actually begins, to
describe which TForm class the DFM belongs to. When compiled into the .exe
file, that header is not present in the DFM resource. You are not seeking
the file stream to the actual beginning of the DFM data before passing it to
ObjectBinaryToText(), so it cannot read the DFM's signature. That is why
the error is occuring.

The easiest way to account for the extra header is to call the file stream's
ReadResHeader() method before calling ObjectBinaryToText(). When I added
that into your code, ObjectBinaryToText() was able to succeed properly.

Your code works on textual DFM files, but only because there are no extra
bytes at the beginning of the text file, and because
TMemoryStream::LoadFromStream() resets the input stream's Position back to 0
automatically before copying the data. Otherwise, the code would have
failed for text DFMs as well since you are leaving the file stream's
Position at 6 when calling LoadFromStream().

With that said, try the following code:

TMemoryStream *fs = new TMemoryStream;
try
{
TFileStream *in = new TFileStream(DFMFilename, fmOpenRead |
fmShareDenyWrite);
try
{
try
{
char tmpbuff[7] = {0};
in->ReadBuffer(tmpbuff, 6);

if( StrComp(tmpbuff, "object") == 0 )
fs->CopyFrom(in, 0);
else
{
in->Position = 0;
in->ReadResHeader();
ObjectBinaryToText(in, fs);
}
}
catch(const Exception &e)
{
MessageDlg("Error parsing dfm file (" + e.Message + ").",
mtWarning, TMsgDlgButtons() << mbOK, 0);
}
}
__finally {
delete in;
}
}
__finally
{
delete fs;
}


Gambit
Back to top
Kenneth de Camargo
Guest





PostPosted: Tue Feb 28, 2006 11:03 pm    Post subject: Re: ObjectResourceToText Reply with quote

Remy Lebeau (TeamB) wrote:

Quote:
I explicitly said it was a DFM for an older version of the VCL.

No, you did not. All you said was that you were loading .dfm files.
You never said anything about their versions.

I could swear I had. Sorry.

Quote:
this is code that worked perfectly (still does) with BCB 6.

Actually, it does not work. I ran your code as-is under BCB 6 and it
fails every time on binary DFM files.

I cleared up too much stuff, I did set In->Position to 0 after reading
the first bytes, but as I deleted some of the comments to post I
deleted that as well, sorry. Still didn't work.

Quote:
The easiest way to account for the extra header is to call the file
stream's ReadResHeader() method before calling ObjectBinaryToText().
When I added that into your code, ObjectBinaryToText() was able to
succeed properly.

That did the trick, thanks.

--
Ken
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.