 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Raul Lorenzo Guest
|
Posted: Sun Feb 19, 2006 5:03 pm Post subject: Variable content differs when executing from IDE Debugger an |
|
|
Hi,
I have this piece of code:
TStream *bsDBBlob=NULL;
bsDBBlob=Consulta->CreateBlobStream(Consulta->FieldByName("contenido_facturacion"),bmRead);
if (bsDBBlob!=NULL)
{
buffer=new TMemoryStream();
try
{
AnsiString tmp;
bsDBBlob->Position=0;
//If I print bsDBBlob->Size to a file it reports 0, and with tooltip
//over variable inside from IDE it reports me bsDBBlob->Size=44100, the
//code works running code from IDE Debugger, but without the IDE, just
//executing the EXE, it raises at exception caused by bsDBBlob->Size=0,
//so buffer->LoadFromStream(bsDBBlob) is unsuccessful.
//Running with only EXE, printed value to file of bsDBBlob->Size=0
buffer->LoadFromStream(bsDBBlob);
buffer->SaveToFile(fichero_);
}
This is strange, it occurs me with C++Builde5, C++Builder6 and now with
BDS2006. It only works if the code is executed from IDE only.
Any Idea? |
|
| Back to top |
|
 |
JD Guest
|
Posted: Sun Feb 19, 2006 6:03 pm Post subject: Re: Variable content differs when executing from IDE Debugge |
|
|
Raul Lorenzo <rlorenb (AT) agalisa (DOT) es> wrote:
| Quote: |
If I print bsDBBlob->Size to a file it reports 0, and with
tooltip over variable inside from IDE it reports me bsDBBlob-
Size=44100,
|
It's been a while since I worked with blobs but with all of
the code that I have, I always performed a seek after they
were created. I don't know if that will make a difference but
you can try:
TBlobStream *inStream = NULL;
TFileStream *outStream = NULL;
try
{
inStream = (TBlobStream*) Consulta->CreateBlobStream( Consulta->FieldByName("contenido_facturacion"), bmRead );
outStream = new TFileStream( fichero_, fmCreate );
inStream->Seek( 0, soFromBeginning );
outStream->CopyFrom( inStream, inStream->Size );
}
catch( Exception &E )
{
//
}
delete inStream;
delete poutStream;
If that doesn't do it for you, try inserting a ShowMessage
directly above that block of code. If that allows the blob to
function as expected, then your program has memory management
problems and/or undefined behavior.
~ JD |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Feb 21, 2006 9:03 am Post subject: Re: Variable content differs when executing from IDE Debugge |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote in message
news:43f8a952$1 (AT) newsgroups (DOT) borland.com...
Use this instead:
try
{
TStream *inStream =
Consulta->CreateBlobStream(Consulta->FieldByName("contenido_facturacion"),
bmRead);
try
{
TStream *outStream = new TFileStream(fichero_, fmCreate);
try {
outStream->CopyFrom(inStream, 0);
}
__finally {
delete outStream;
}
}
__finally {
delete inStream;
}
}
catch(const Exception &E)
{
//
}
Or this:
#include <memory>
try
{
std::auto_ptr<TStream>
inStream(Consulta->CreateBlobStream(Consulta->FieldByName("contenido_factura
cion"), bmRead));
std::auto_ptr<TStream> outStream(new TFileStream(fichero_,
fmCreate));
outStream->CopyFrom(inStream, 0);
}
catch(const Exception &E)
{
//
}
In particular, you should NEVER cast the return value of CreateBlobStream().
DataSets are free to implement any kind of stream type they want internally.
You are not guaranteed to get a TBlobStream. That is why CreateBlobStream()
returns a generic TStream* - to hide what it actually uses internally.
Also, specifying 0 for the Size in CopyFrom() removes the need for manualy
seeking.
Gambit |
|
| Back to top |
|
 |
|
|
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
|
|