How do you extract a bitmap from a TGraphicField?

Viewed 1389

I am going nuts.

Here's what I am doing

  1. Drop a TClientDataset, a TImage, and a TButton on a form.
  2. Set the Clientdataset1.Filename to biolife.xml
  3. Double click on the button and add the following code:

    procedure TForm31.Button1Click(Sender: TObject);
    var
      BF: TBlobField;
      BS: TStream;
      BM: TBitmap;
    begin
      ClientDataset1.Open;
      ClientDataset1.First;
      BF :=  ClientDataSet1.FieldByName('Graphic') as TBlobField;
      BS := ClientDataSet1.CreateBlobStream(BF, bmRead);
      BS.Position := 0;
      BM := TBitmap.Create;
      try
        BM.LoadFromStream(BS);
      finally
        BM.Free;
      end;
    end;
    

Run it. When I do, I get "Bitmap image is not valid".

Huh? That data has been a bitmap for years -- what is wrong?

2 Answers
Related