Saving a Jpeg image into a binary field
I am trying to copy a JPeg image to a Paradox 7 table. I have the JPeg both
as a file and as in image in a TJPegImage component. I cannot get any code
to work because I can't get the database field to be of type BLOB. Here is
the routine:
// tblPicture is a Paradox 7 table
// tblPicture.FieldByName('Picture') is a BINARY FIELD (I have also made
it a graphic field)
// What do you mean when you say a Binary field is equivalent to BLOB,
// "and should be represented by a TBlobField object" ? That is really
what
// my problem is -- I cannot get the types matched up between the database
// field and the blobstream to even CREATE the blob stream. I do not know
how
// make a paradox field of type BLOB, only of type Binary. When I look at
this
// field in Database Desktop, it is a "BLOB Binary". What am I doing
wrong?
// ERROR MESSAGE: "Incompatible types: 'TBlobField' and 'TTable'"
procedure TForm1.SaveToDatabase(JPegImage:TJPegImage; P:TPanel);
var
BS: TBlobStream;
begin
try
tblPicture.Open;
// I tried the commented-out line below because it is a FIELD
// BS := TBlobStream.Create(tblPicture.FieldByName('Picture'), bmWrite);
BS := TBlobStream.Create(tblPicture, bmWrite); // THIS LINE THROWS
THE ERROR !!!
tblPicture.Insert;
begin // P.Hint contains the path of the JPeg file
FileStream.CopyFrom(BlobStream, BlobStream.Size);
tblPicture.FieldByName('Path').AsString := ExtractFilePath(P.Hint);
tblPicture.FieldByName('FileName').AsString :=
ExtractFileName(P.Hint);
tblPicture.Post;
end;
finally
BlobStream.Free;
end;
end;
How do I get the "Picture" field to be compatible with type BLOB instead of
type Binary?