Board index » delphi » HELP: Trouble putting files into BLOBs

HELP: Trouble putting files into BLOBs

Hey all,
        I am having great difficulty saving a file in a BLOB field.
        My idea is this, simply building a file archive where you can
check files in and out of a Local InterBase table that has BLOB fields in it.
I am finding thi more difficult than I anticipated.  I started using
LoadFromFile in the following manner:

 FieldByName('BlobField').LoadFromFile(sFileToBLOB);

where all is within a 'with tblBlobs...' clause.  The field BlobField
is just an InterBase BLOB, and according to all the help I have read,
LoadFromFile loads a file directly into a BLOB field.  But, I get a
'Field identifier expected' error from the compiler after the first period.
I can't use AsString or any of that ilk because I just want the raw BLOB
(I am talking word files, excel files, andy file!).  It works ok with
BMP files, actually saving a TImage.Picture in the field with an Assign
statement.
        I even tried creating a TBlobField component, and saving to it.
The following line:

  TempBlob.LoadFromFile(<my file name>);

compiled just fine, but GPFed when I ran it.  What is going on here?
        I saw something about SetData reading raw stuff, but they ere talking
from memory, and I want to read from a file.  This doesn't seem lie it should
be a big deal.
        If anyone can tell me what I am doing wrong, or the correct FAQ
to read on the problem, I will be eternally grateful.  Thanks!

Joe Kaufman

 

Re:HELP: Trouble putting files into BLOBs


On 14 Feb 96 21:04:27 CST, bv01...@acad.drake.edu wrote:

Quote
>    I am having great difficulty saving a file in a BLOB field.
>    My idea is this, simply building a file archive where you can
>check files in and out of a Local InterBase table that has BLOB fields in it.
>I am finding thi more difficult than I anticipated.  I started using
>LoadFromFile in the following manner:

> FieldByName('BlobField').LoadFromFile(sFileToBLOB);

>where all is within a 'with tblBlobs...' clause.  The field BlobField
>is just an InterBase BLOB, and according to all the help I have read,
>LoadFromFile loads a file directly into a BLOB field.  But, I get a
>'Field identifier expected' error from the compiler after the first period.
>I can't use AsString or any of that ilk because I just want the raw BLOB
>(I am talking word files, excel files, andy file!).  It works ok with
>BMP files, actually saving a TImage.Picture in the field with an Assign
>statement.

The line of code you cite *should* produce the "Field identifier expected"
compile-time error. The FieldByName method of the TTable (as well as the
Fields property) return a value of type TField -- not TMemoField or
TBlobField. The TField component (from which the TBlobField component
descends) does not have a LoadFromFile method, hence the error. If you do
not define TFields (a TBlobField in this case), you can still use the
FieldByName method, just typecast the TField return value as TBlobField, as
in:

  TBlobField(FieldByName('BlobField')).LoadFromFile(sFileToBLOB);

Quote
>    I even tried creating a TBlobField component, and saving to it.
>The following line:

>  TempBlob.LoadFromFile(<my file name>);

>compiled just fine, but GPFed when I ran it.  What is going on here?
>    I saw something about SetData reading raw stuff, but they ere talking
>from memory, and I want to read from a file.  This doesn't seem lie it should
>be a big deal.
>    If anyone can tell me what I am doing wrong, or the correct FAQ
>to read on the problem, I will be eternally grateful.  Thanks!

I was able to successfully copy the contents of a binary file (in this case
a small Paradox table) into a BLOB column in a Local InterBase Server
(LIBS) table with the code:

  procedure TForm1.Button1Click(Sender: TObject);
  var
    Dire: String;
  begin
    Dire := 'c:\internet\category.db';
    with Table1 do begin
      if not (State in [dsInsert, dsEdit]) then
        Edit;
      TBlobField(FieldByName('BITMAP')).LoadFromFile(Dire);
      Post;
    end;
  end;

Unless there is something wrong with your BLOB column, something wrong in
the code (not a syntax error, but perhaps and incorrect value in the
variable containing the binary file name), or some other problems, you
should be able to do this.

What type (SUB_TYPE) of BLOB column was used? See page 61 of the LIBS
manual Data Definition Guide, in the section "BLOB Subtypes," for more on
InterBase BLOB column types. Basically, you should use subtype 1 only for
storing text values, subtype 0 or a user-defined subtype for binary data.

**************************************************************************
Steve Koterski                  "Results! Why, man, I have gotten a lot of
Product Group Manager           results. I know several thousand things
Delphi Technical Support        that won't work."
Borland International, Inc.                    -- Thomas Edison, 1847-1931

Other Threads