#21 TBlobField problem

Win32_only
closed-fixed
Memo (7)
5
2003-12-14
2003-12-11
Rainer M. Krug
No

Hi

I try to save a stream into a blob field and I want to
retrieve it again. I use the two procedures below.
Example: Strem.Size is always 81924 (see first
///////////////////
bewlow) and when loading it is only correct at first
record (see second
///////////////////
bewlow)

it must be a TDBF problem, as if I replace TDBF with
TTable (also dBase), it gives the same sizes.

Rainer (RMK@krugs.de)

procedure TLocList.SaveToDBaseRecord(LocListDB: TDataSet);
var
Stream: TMemoryStream;
fPoints: TField;
begin
if not assigned(LocListDB) then
raise Exception.Create('LocListDB must be a valid
reference
to a TDataSet!');

fPoints := LocListDB.FieldByName('Points');
if not fPoints.IsBlob then
raise Exception.Create('The field "Points" must be
of type
TBlobField!');

Stream := TMemoryStream.Create;
try
///////////////////
SavePointsToStream(Stream);
//<== Stream.Size is always 81924
///////////////////
TBlobField(fPoints).LoadFromStream(Stream);
finally
Stream.Free;
end;

LocListDB.FieldByName('AutoScale').AsBoolean :=
AutoScale;
LocListDB.FieldByName('LineColor').AsInteger :=
LineColor;
end;

procedure TLocList.SavePointsToStream(Stream: TStream);
var
i: Integer;
begin
if not assigned(Stream) then
raise Exception.Create('Stream must be a valid
reference to
a TStream!');

i := Count;
Stream.WriteBuffer(i, SizeOf(Integer));
for i := 0 to Count - 1 do
Loc[i].SaveToStream(Stream);
end;

procedure TLocList.LoadFromDBaseRecord(LocListDB:
TDataSet);
var
Stream: TStream;
fPoints: TField;
begin
if not assigned(LocListDB) then
raise Exception.Create('db must be a valid
reference to a
TDataSet!');

fPoints := LocListDB.FieldByName('Points');
if not fPoints.IsBlob then
raise Exception.Create('The field "Points" must be
of type
TBlobField!');

///////////////////
Stream := LocListDB.CreateBlobStream(fPoints, bmRead);
//<== first Record: correct size
//<== second Record: wong size
///////////////////
try
LoadPointsFromStream(Stream);
finally
Stream.Free;
end;
FAutoScale :=
LocListDB.FieldByName('AutoScale').AsBoolean;
FLineColor :=
LocListDB.FieldByName('LineColor').AsInteger;
end;

procedure TLocList.LoadPointsFromStream(Stream: TStream);
var
i: Integer;
STC: Integer;
begin
if not assigned(Stream) then
raise Exception.Create('Stream must be a valid
reference to
a TStream!');

Clear;
Stream.ReadBuffer(STC, SizeOf(Integer));
for i := 0 to STC - 1 do
Add.LoadFromStream(Stream);
end;

Discussion

  • Micha Nelissen
    Micha Nelissen
    2003-12-14

    • status: open --> closed-fixed
     
  • Micha Nelissen
    Micha Nelissen
    2003-12-14

    Logged In: YES
    user_id=28190

    You reported it was fixed in version 6.3.1.

    Micha.