Solved

Pictures in DBF

Posted on 2000-04-17
1
283 Views
Last Modified: 2010-04-04
how do you add pictures at design and runtime into a database(DBF file). Basically how do you do what the sample animals.DBF file does.
0
Comment
Question by:frangers99
1 Comment
 
LVL 7

Accepted Solution

by:
Motaz earned 10 total points
Comment Utility
Picture can be loaded into dbf file using Binary field (BLOB) moreover you can load any file in this field. If you want example you can download my Electronic Book and Delphi book from my site:

www.gocities.com/motaz1

This is the example of my EB:

Blob Field (Binary):


Blob field (Binary Large OBject) used in Paradox tables to store any kind of data, including any file type. It is like a memo, (Virtualy there is no limit in size). Below example illustrates how to store file in a Blob field (Blob field in this example is called "Data"):

procedure TForm1.btLoadClick(Sender: TObject);
var
  MyFile: TFileStream;
  MyBlobStream: TBlobStream;
begin
  if OpenDialog1.Execute then
  begin
   try
    Table1.Append;
    (*** Save file name in a string field called "File" ***)
    Table1.FieldByName('File').AsString:=
      ExtractFileName(OpenDialog1.FileName);

    (*** Open the file using file stream type ***)
    MyFile:= TFileStream.Create(OpenDialog1.FileName, fmOpenRead);

    (*** Create the Blob stream and link it to the Blob field ***)
    MyBlobStream := TBlobStream.Create(
      TBlobField(Table1.FieldByName('Data')), bmReadWrite);

    (*** Copy all file data from the external file to Blob field ***)
    MyBlobStream.CopyFrom(MyFile, 0);

    Table1.Post;
    MyFile.Free;
   except
     on E: Exception do
       Table1.Cancel;
   end; // try

  end;  // if OpenDialog
end;


Next example illustrates how to read file from a Blob field:

procedure TForm1.btOpenClick(Sender: TObject);
var
  MyBlob: TBlobStream;
  MyFile: TFileStream;
begin
  (*** Create Blob stream and link it to existing Blob data ***)
  MyBlob:= TBlobStream.Create(
    TBlobField(Table1.FieldByName('Data')), bmRead);

  (*** Create a temporary file to extract the Blob file on it ***)
  MyFile:= TFileStream.Create(ExtractFileName(
    Table1.FieldByName('File').AsString), fmCreate);

  (*** Copy file data from the Blob to temporary file ***)
  MyFile.CopyFrom(MyBlob, 0);

  MyFile.Free;

  (*** Open the file ***)
  ShellExecute(handle, 'open',
    PChar(ExtractFileName(Table1.FieldByName('File').AsString)),
    nil, nil, sw_Normal);
end;


Motaz



0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

16 Experts available now in Live!

Get 1:1 Help Now