Solved

Borland C++ BUilder: BLOB read and write?

Posted on 2001-08-01
7
2,030 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

687 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