Solved

Borland C++ BUilder: BLOB read and write?

Posted on 2001-08-01
7
2,000 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

831 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