Solved

Borland C++ BUilder: BLOB read and write?

Posted on 2001-08-01
7
1,952 Views
Last Modified: 2012-06-27
A table will form as below after running the C++ Builder code:

1   [BLOB]  [*BLOB*]  [BLOB]  [BLOB]  [BLOB] [BLOB] [Blob]
2   [BLOB]  [*BLOB*]  [BLOB]  [BLOB]  [BLOB] [BLOB] [Blob]
3   ......

1000[BLOB]  [*BLOB*]  [BLOB]  [BLOB]  [BLOB] [BLOB] [Blob]



I need that, after only click the second [BLOB], all data in this column of all raws will be saved in
ascii format. Howevr, only the data in the first BLOB was saved, all other data was NOT saved in the
file. How to modify it?
High points will be given if your modification does work!

//_________________ part of code _________________
void TMainForm::ExportBLOB(AnsiString FileName, AnsiString FieldName)
{
 int SaveNo = DBTable->RecNo;  
 DBTable->First();DBTable->Next();  
 TFileStream* File=new TFileStream(FileName, fmCreate);  
 while(!DBTable->Eof){    //***

 TField* Field=DBTable->FieldByName(FieldName);
 TFieldType FieldType=Field->DataType;
 if(FieldType!=ftBlob)
 throw Exception("Invalid Call To ExportBlob() - Field Not A BlobType");

 TBlobField* ThisBlob;
 ThisBlob=(TBlobField*)Field;
 TBlobStream* ThisBlobStream;
 ThisBlobStream=new TBlobStream(ThisBlob, bmRead);

 int PointsToRead=ThisBlobStream->Size/sizeof(short);
 if(PointsToRead<=0)
 {
     delete ThisBlobStream;
     return;
 }

 short* Data=new short[PointsToRead];

 ThisBlobStream->Seek(0, soFromBeginning);
 ThisBlobStream->Read(Data, ThisBlobStream->Size);

 for(int i=0; i<PointsToRead; i++)
 {
     AnsiString Text;
     Text+=Data[i];
     Text+="\n";  
     File->Write(Text.c_str(), Text.Length());
 }

 delete ThisBlobStream;
 delete [] Data;
 DBTable->Next();DBTable->Next();DBTable->Next();DBTable->Next();
 DBTable->Next();DBTable->Next();  
 }    //***
 delete File;    
 DBTable->RecNo = SaveNo;

}
0
Comment
Question by:Johncili
  • 5
  • 2
7 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 300 total points
ID: 6341005
I think you have something wrong with the following line:
int PointsToRead=ThisBlobStream->Size/sizeof(short);
0
 
LVL 30

Expert Comment

by:Axter
ID: 6341010
What is ThisBlobStream->Size?
Can you post the structure for ThisBlobStream?
Why are you divideing it by sizeof(short)?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6341023
You should also change your loop to the following:

for(int i=0; i<PointsToRead; i++)
{
    AnsiString Text = Data[i];
    Text+="\n";  
    File->Write(Text.c_str(), Text.Length());
}
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Johncili
ID: 6341372
Axter,

All your answers do not work for the question. Only first [BLOB] is read and write to the file. Then other [BLOB] are just passed with out writing data to file. I guess following code arise problem:
TBlobField* ThisBlob;
ThisBlob=(TBlobField*)Field;
TBlobStream* ThisBlobStream;

0
 
LVL 30

Expert Comment

by:Axter
ID: 6342024
>>All your answers do not work for the question.
My last two comments are not suppose to be answers.

Could you please post an answer to the following questions:
What is ThisBlobStream->Size?
Can you post the structure for ThisBlobStream?
Why are you divideing it by sizeof(short)?

Can you put a breakpoint on the following line, and see what is the value of PointsToRead when you're running the code?
for(int i=0; i<PointsToRead; i++)
0
 

Author Comment

by:Johncili
ID: 6342116

The only problem is that, it wrote a BLOB data, other BLOB's data are not written into the file. This is the problem.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6342199
Why do you have "DBTable->Next();" multiple times?

DBTable->Next();DBTable->Next();DBTable->Next();DBTable->Next();
DBTable->Next();DBTable->Next();  

Shouldn't that be called only once?

Can you post the structure for DBTable?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now