How can I streaming a published TBitmap property from DFM?

119 views Asked by At

I created a published TBitmap property in Delphi 7. I can set its value by the editor in design time and if I recall the editor I can see the right picture. But when I save, close and reopen the form, the TBitmap property is empty. What is missing? I know there is the loaded virtual method. But what should I do in it?

TCustomComponent = class ( TComponent )
  private
    fBitmap : TBitmap;

  protected
    procedure loaded; override;
    procedure setBitmap( bitmap_ : TBitmap );

  public
    constructor create( owner_ : TComponent ); override;
    destructor destroy; override;

  published
    property bitmap : TBitmap read fBitmap write setBitmap;

end;

procedure TCustomComponent.loaded;
begin
  inherited loaded;
  // ???
end;

procedure TCustomComponent.setBitmap( bitmap_ : TBitmap );
begin
  fBitmap.assign( bitmap_ );
end;

constructor TCustomComponent.create( owner_ : TComponent );
begin
  inherited create( owner_ );
  fBitmap := TBitmap.create;
end;

destructor TCustomComponent.destroy; 
begin
  fBitmap.free;
  inherited destroy;
end;
1

There are 1 answers

0
David Heffernan On BEST ANSWER

I believe that the conventional way to deal with this is to use TPicture instead of TBitmap for published properties. The TPicture component comes with support for streaming, and a designer.