Solved

Pictures in DBF

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtualstringtree carsh after invalidate for while 5 87
indy Tmemory stream non latin charcter issue 2 98
Printing problem 2 81
Dev Express grid collapse 2 39
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

24 Experts available now in Live!

Get 1:1 Help Now