How to read a TBlobfield from a query

40 Views Asked by At

Here is my problem. I have a MS ACCESS table (id , firstname, name, file). The file field is of OLE object type and contains a pdf file for each record.

I am using DELPHI XE 5 and FireDAC as data components (TFDConnection, TFDTable, TFDQuery). I am able to store data in the file field but not able to read it.

When I use TFDQuery I am not able to read data in the file field. Here is what a did to read:

procedure TForm1.Button8Click(Sender: TObject);
var fx:TmemoryStream;   bl:TBlobField;
begin
    fx:=TMemoryStream.create;
    query1.open;

    bl:= TBlobField (query1.FieldByName('file')) ;
    
    bl.SaveToStream(fx);    
    fx.SaveToFile('c:\exportedfile.pdf');
    fx.free;
end;

The script works but the problem is that the file is exported as a 4kb unreadable file, while its real size is more than 100kb. There is no such problem if I use a TFDTable.

0

There are 0 best solutions below