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;
I believe that the conventional way to deal with this is to use
TPicture
instead ofTBitmap
for published properties. TheTPicture
component comes with support for streaming, and a designer.