?
Solved

Borland C++ BUilder: BLOB read and write?

Posted on 2001-08-01
7
Medium Priority
?
2,044 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 600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

801 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