Save to Blob Field

Dear Experts, Happy New Year !

      Please help me how to save windows meta file (.wmf) into local interbase table ( Blob field ).

Thanks from apin
pc_melsaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
Hi
Graphic Blob fields and TDBImage only support BMP data.  You will need to use a raw binary blob field to store metafile data,with a timage.  
 
here is from borland:

Question and Answer Database

FAQ878D.txt   Save and load metafiles in a BLOB field without using DBImage
Category   :VCL
Platform    :All
Product    :All 32 bit  

Question:
How can I save and load metafiles in a BLOB field without using the
DBImage component?


Answer:
The following example demonstrates saving metafile images to a
database as they exist on the disk, preserving any Placeable metafile
headers that may be present in the Metafile. The image is displayed
from the database in a TImage component.

Example:

unit Unit1;

interface

{$IFDEF WIN32}
  uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, Db,
      DBTables;
{$ELSE}
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, DBTables, DB, Grids, DBGrids, ExtCtrls, StdCtrls;
{$ENDIF}

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Image1: TImage;
    Button1: TButton;
    Table1Name: TStringField;
    Table1WMF: TBlobField;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
  private
    { Private declarations }
    FileName : string; {Used to hold a temp file name}
    procedure LoadWMFFromDatabase; {loads a WMF from the database}
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
 {Used for loading metafiles}
  OpenDialog1.Filter := 'Metafiles (*.wmf)|*.wmf';
  OpenDialog1.Options := [ofHideReadOnly, ofNoChangeDir];
  Image1.Stretch := true;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 {Erase the temp file if it exists}
  if FileName <> '' then
    DeleteFile(FileName);
end;

{This function gets a temporary file name form the system}
function GetTemporaryFileName : string;
{$IFNDEF WIN32}
  const MAX_PATH = 144;
{$ENDIF}
var
 {$IFDEF WIN32}
  lpPathBuffer : PChar;
 {$ENDIF}
  lpbuffer : PChar;
begin
 {Get the file name buffer}
  GetMem(lpBuffer, MAX_PATH);
 {$IFDEF WIN32}
 {Get the temp path buffer}
  GetMem(lpPathBuffer, MAX_PATH);
 {Get the temp path}
  GetTempPath(MAX_PATH, lpPathBuffer);
 {Get the temp file name}
  GetTempFileName(lpPathBuffer,
                  'tmp',
                  0,
                  lpBuffer);
 {Free the temp path buffer}
  FreeMem(lpPathBuffer, MAX_PATH);
 {$ELSE}
 {Get the temp file name}
  GetTempFileName(GetTempDrive('C'),
                  'tmp',
                  0,
                  lpBuffer);
 {$ENDIF}
 {Create a pascal string containg}
 {the  temp file name and return it}
  result := StrPas(lpBuffer);
 {Free the file name buffer}
  FreeMem(lpBuffer, MAX_PATH);
end;

procedure TForm1.LoadWMFFromDatabase;
var
  FileStream: TFileStream; {a temp file}
  BlobStream: TBlobStream; {the WMF Blob}
begin
  Image1.Picture.Metafile.Assign(nil);
 {Create a blob stream for the WMF blob}
  BlobStream := TBlobStream.Create(Table1WMF, bmRead);
  if BlobStream.Size = 0 then begin
   BlobStream.Free;
   Exit;
  end;
 {if we have a temp file then erase it}
  if FileName <> '' then
    DeleteFile(FileName);
 {Get a temp file name}
  FileName := GetTemporaryFileName;
 {Create a temp file stream}
  FileStream := TFileStream.Create(FileName,
                                   fmCreate or fmOpenWrite);
 {Copy the blob to the temp file}
  FileStream.CopyFrom(BlobStream, BlobStream.Size);
 {Free the streams}
  FileStream.Free;
  BlobStream.Free;
 {Dispaly the image}
  Image1.Picture.Metafile.LoadFromFile(FileName);
end;

{Save a wmf file to the database}
procedure TForm1.Button1Click(Sender: TObject);
var
  FileStream: TFileStream; {to load the wmf file}
  BlobStream: TBlobStream; {to save to the blob}
begin
 {Allow the button to repaint}
  Application.ProcessMessages;
  if OpenDialog1.Execute then begin
   {Turn off the button}
    Button1.Enabled := false;
   {Assign the avi file name to read}
    FileStream := TFileStream.Create(OpenDialog1.FileName,
                                     fmOpenRead);
    Table1.Edit;
   {Create a BlobStream for the field Table1WMF}
    BlobStream := TBlobStream.Create(Table1WMF, bmReadWrite);
   {Seek to the Begginning of the stream}
    BlobStream.Seek(0, soFromBeginning);
   {Delete any data that may be there}
    BlobStream.Truncate;
   {Copy from the FileStream to the BlobStream}
    BlobStream.CopyFrom(FileStream, FileStream.Size);
   {Free the streams}
    FileStream.Free;
    BlobStream.Free;
   {Post the record}
    Table1.Post;
   {Load the metafile in to a TImage}
    LoadWMFFromDatabase;
   {Enable the button}
    Button1.Enabled := true;
  end;
end;

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  if (Sender as TDataSource).State = dsBrowse then
    LoadWMFFromDatabase;
end;

end.


link to above text:
http://www.borland.com/devsupport/delphi/faq/FAQ878D.html

Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pc_melsaAuthor Commented:
Thanks !
0
pc_melsaAuthor Commented:
Graphic Blob fields and TDBImage not only support BMP data, but JPG and JPEG as well.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

intheCommented:
yes that is true :-)
hapy new year :-)
0
pc_melsaAuthor Commented:
Dear Mr. Barry !
    It did not work with Local Interbase Table ( it is just for BDE table )

Best regards,
apin

0
intheCommented:
hi,
does this mean the answer is no help ?
sorry about that, would this help instead:

http://x33.deja.com/[ST_rn=qs]/getdoc.xp?AN=204180820&CONTEXT=946695189.1800404996&hitnum=1

let me know if it helps or not and if not i will ask a  question on your behalf.
Regards Barry

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.