FROM: The Nomad <tnomad@digital.net>
SUBJECT: Re: using Canvas in a home made component (2)
DATE: 24 Jul 1995 11:57:45 GMT


>TScrollingPaintBox = class(TScrollingWinControl)
>private
>Canvas: TCanvas;
>public
>constructor Create(aOwner:TComponent);
>end;

I would change the definition as follows:

TScrollingPaintBox = class(TScrollingWinControl)
  private
    FCanvas: TCanvas;
  public
    constructor Create(aOwner:TComponent); override;
    destructor Destroy; override;
    property Canvas: TCanvas read FCanvas;
end;

constructor TScrollingPaintBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FCanvas := TControlCanvas.Create;
  TControlCanvas(FCanvas).Control := Self;
end;

destructor TScrollingPaintBox.Destroy;
begin
  FCanvas.Free;
  inherited Destroy;
end;


A TControlCanvas is important because it creates a DC that belongs to the 
HWND of the control.  Also, override is important on your constructor 
and destructor to insure that they are actually called. I hope this 
helps.

************************************
*           The Nomad              *
*        tnomad@digital.net        *
************************************
