Problem with Delphi 7 , Pervasive and ADO accessing blobs


2003-09-23 01:16:31 AM
delphi219
I'm trying to access blob data created by a product called MailCenter
Tracking System which uses Btrieve files to store the data. The problem is
that the blob fields are not being retrieved correctly by either ADO 2.5 via
ODBC or the Pervasive ODBC driver. The resulting bitmap stored in the blob
field is not recognized as a bitmap by the image control or any bitmap
editor or viewer. The original application that created the bitmap has no
problems. As far as I can tell the bitmaps are stored without any
encryption in the blob fields. MTS uses InfoPower controls to access the
blobs. Writing similar code in VB6 has the same problem. Is there a
problem with ADO accessing Btrieve file data using Pervasive? Am I missing
something?
Examples of numerous methods used to retrieve the blob:
procedure TForm1.LoadPictureFromFile;
var
Field: TField;
Memo:string; //TMemoField;
MemoField: TMemoField;
BlobField: TBlobField;
FileName:string;
F1: TextFile;
i:integer;
const c_mem = 4000;
begin
{
with mtsdata.ADODataSet1 do
begin
open;
First;
Next;
FileName:='d' + FieldbyName('recip_id').value + '.bmp';
VarSaveToFile(FieldbyName('SIG').value, FileName);
end;
}
try
getmem(a,c_mem+1);
for i:=0 to c_mem+1 do
a[i]:=#0;
with mtsdata.ADODataSet1 do
begin
open;
First;
next;
next;
BlobField:=TBlobField(FieldbyName('SIG'));
BlobField.GetData(a);
// MemoField:=TMemoField(FieldbyName('SIG'));
// MemoField.GetData(a);
// Memo:=FieldbyName('SIG').asstring;
// strpcopy(a, Memo);
FileName:='d' + FieldbyName('recip_id').value + '.bmp';
if (fileexists(Filename)) then
deletefile(FileName);
//BlobField.SaveToFile(FileName);
end;
i:=0;
AssignFile(F1, FileName );
rewrite(F1);
for i:=0 to c_mem do
begin
ch := a[i];
write(F1,ch);
//if MemoField.Size = i then break;
//if length(Memo) = i then break;
if BlobField.Size = i then break;
if i = c_mem then begin break; end;
end;
finally
freemem(a);
CloseFile(F1);
end;
if (fileexists(Filename)) then
image1.picture.LoadFromFile(FileName);
end;
procedure TForm1.LoadPictureFromDatabase;
var
BlobField:TBlobField;
BS: TStream;
img:Tbitmap;
begin
with mtsdata.ADODataSet1 do
begin
open;
First;
//recip_id
//Man_num
//Blobfield := FieldbyName('SIG');
BlobField:=TBlobField(FieldbyName('SIG'));
if BlobField.IsNull then
begin
Exit;
end;
BS:=CreateBlobStream(BlobField,bmRead);
BS.Seek(0,soFromBeginning);
BS.Position:=0;
img:=TBitmap.Create;
img.LoadFromStream(BS);
image1.picture.assign(img);
img.Free;
bs.Free;
end;
end;
procedure TForm1.BlobStreamFromDatabase;
VAR
P:TADOBlobStream;
BlobField: TBlobField;
BEGIN
with mtsdata.ADODataSet1 do
begin
open;
First;
next;
BlobField:=TBlobField(FieldbyName('SIG'));
end;
P:=TADOBlobStream.Create(BlobField, bmRead);
P.Seek(0, soFromBeginning);
try
image1.Picture.Bitmap.LoadFromStream(P);
finally
P.Free
end;
end;