Solved

Blob Fields  and BlockWrite/Read

Posted on 1998-07-04
7
312 Views
Last Modified: 2010-04-04
Hi,

I am trying to write (and read) the contents of a blob field to a file using BlockWrite.

I am trying to use the following code but it always gives me an I/O Error 87 - what ever that is, errors being documented the way they are.

    ImageStream := TBlobStream.Create(FieldByName('Image') as TBlobField,
      bmRead);
    Blockwrite(TXMessageFile, ImageStream, ImageStream.Size);

Any ideas?

Thanks

Chris

0
Comment
Question by:ChrisBerry
  • 4
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
vladika earned 50 total points
ID: 1357099
Use TBlobField's method SaveToFile or SaveToStream

For example
  TBlobField(Dataset.FieldByName('Image')).SaveToFile(FileName);

You cannot use BlockWrite as you write.
You must pass Buffer to BlockWrite.
And ImageStream is not buffer.

0
 
LVL 3

Expert Comment

by:vladika
ID: 1357100
If you still want use BlockWrite you can try this

var Buffer: Pointer;
      MemStream: TMemoryStream;
.............
  MemStream := TMemoryStream.Create;
  try
    TBlobField(DataSet.FieldByName('Image')).SaveToStream(MemStream);
    Buffer := MemStream.Memory;
    Blockwrite(TXMessageFile, Buffer^, MemStream.Size);
// use Buffer^ !!!! Stream is not buffer
  finally
    MemStream.Free;
  end;


0
 

Author Comment

by:ChrisBerry
ID: 1357101
Thanks,

The reason I am using BlockWrite is because this bit is only part of a file I am creating.

I knew I needed a buffer but could not figure out the details.

Thanks again.

Chris

0
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.

 
LVL 3

Expert Comment

by:vladika
ID: 1357102
Hi, Chris

> The reason I am using BlockWrite is because this bit is only part of a file I am creating.

It is not problem. You can use TFileStream for work with
part of file as well as BlockWrite/BlockRead.

Vladika.

0
 

Author Comment

by:ChrisBerry
ID: 1357103
Hi Vladika,

>It is not problem. You can use TFileStream for work with
>part of file as well as BlockWrite/BlockRead.

By this do you mean using TFileStream or using 'SaveToFile' method?

I thought 'SaveToFile' always re-wrote the file.

Chris


0
 
LVL 3

Expert Comment

by:vladika
ID: 1357104
Hi Chris

You are right. I mean TFileStream of course.
I intend you may use TFileStream instead of conventional file I/O

Vladika

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2501671
Bought this Q
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

815 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

8 Experts available now in Live!

Get 1:1 Help Now