Solved

Pictures in DBF

Posted on 2000-04-17
1
291 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
ID: 2725512
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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