Solved

Borland C++ BUilder: BLOB read and write?

Posted on 2001-08-01
7
1,994 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 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

10 Experts available now in Live!

Get 1:1 Help Now