Solved

Pictures in DBF

Posted on 2000-04-17
1
299 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
[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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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