Board index » delphi » double buffering

double buffering

is there something like double buffering here...?
i mean...like in java... some kinda offScreen stuff... and then painting
on the screen...
and how..?

thankz...

 

Re:double buffering


Create a TBitmap.  Use TBitmap.Canvas to draw on the bitmap.  Copy the
TBitmap to the form canvas (or a control canvas).

On Fri, 19 Feb 1999 06:50:38 +0100, NuCLeaR <ti...@jambol.bse.bg>
wrote:

Quote
>is there something like double buffering here...?
>i mean...like in java... some kinda offScreen stuff... and then painting
>on the screen...
>and how..?

>thankz...

Chris Hill
Chris...@aol.com

Re:double buffering


Chris...@aol.com wrote on 19.02.99 in article <36ccf1d7.684035...@forums.borland.com>:

Quote
> [...]
> Create a TBitmap.  Use TBitmap.Canvas to draw on the bitmap.  Copy the
> TBitmap to the form canvas (or a control canvas).

 This indeed speeds  up things. But is there a  way to "replace" a
 control's  canvas?  Consider  this  situation  ("aControl"  is  a
 thirdparty-component):

 aControl.Paint;
 Var
   i : integer;
 Begin
   For i := 1 To NumOfLines Do
     PrepareTheLine(i);
 End;

 aControl.PrepareTheLine(i : Integer);
 Var                { private method }
   S : String;
 Begin
   {...
        set Canvas-properties (font, color etc.) depending on "i"
        get contents of line "i" into "S"
   ...}
   WriteStringOut(S, i);
 End;

 aControl.WriteStringOut(Const S : String; LineNo : Integer);
 Begin
   {...
        write "S" onto Canvas
   ...}
 End;

        The method 'WriteStringOut()' is declared virtual and I've
 allready  overridden it  with a  method using  the technique  you
 described.  Works well.  But since  there's  a  lot to  do in  my
 'WriteStringOut'  I  thought,  it  would  be  better  to override
 'Paint()'  and  replace  the  (inherited)  =Canvas=  there with a
 bitmap's canvas  so I could  do the painting  for the whole  page
 (not only  line by line)  an the memory-bitmap  and then 'Draw()'
 the  whole page  at once.  - Unfortunately  I failed.  There's no
 (working) 'Assign()'-method  for a Canvas.  So I wonder  if it is
 possible at all, what I tried to describe?

 MyControl.Paint;                { Save/replace inherited Canvas }
 |_
   aControl.Paint;
   |_
     aControl.PrepareTheLine();           { used replaced canvas }
     |_
       MyControl.WriteStringOut();        { used replaced canvas }
      _|
    _|
  _|
 |
 MyControl.Paint;       { restore inherited Canvas / Draw onto it }

--
        Matthias

Re:double buffering


I'm not sure if there is a way to do this.  The only thing I can think
of is to use the Handle property.  I'll let you test it.. <g> (I don't
know why it would fail, but I've never done it so I can't promise
anything)

Outline:

procedure MyControl.Paint;
var
  SavedDC : HDC;
  buffer : TBitmap;
begin
  SavedDC := Canvas.Handle;
  { Create and initialize the buffer bitmap }
  Canvas.Handle := buffer.Canvas.Handle;
  inherited Paint;
  Canvas.Handle := SavedDC;
  { copy the buffer to the Canvas }
  { free the bitmap }
end;

On Fri, 19 Feb 1999 09:39:00 +0200, Matth...@OLN.ComLink.APC.org

Quote
(Matthias Watermann) wrote:

>Chris...@aol.com wrote on 19.02.99 in article <36ccf1d7.684035...@forums.borland.com>:

>> [...]
>> Create a TBitmap.  Use TBitmap.Canvas to draw on the bitmap.  Copy the
>> TBitmap to the form canvas (or a control canvas).

> This indeed speeds  up things. But is there a  way to "replace" a
> control's  canvas?  Consider  this  situation  ("aControl"  is  a
> thirdparty-component):

> aControl.Paint;
> Var
>   i : integer;
> Begin
>   For i := 1 To NumOfLines Do
>     PrepareTheLine(i);
> End;

> aControl.PrepareTheLine(i : Integer);
> Var                { private method }
>   S : String;
> Begin
>   {...
>        set Canvas-properties (font, color etc.) depending on "i"
>        get contents of line "i" into "S"
>   ...}
>   WriteStringOut(S, i);
> End;

> aControl.WriteStringOut(Const S : String; LineNo : Integer);
> Begin
>   {...
>        write "S" onto Canvas
>   ...}
> End;

>        The method 'WriteStringOut()' is declared virtual and I've
> allready  overridden it  with a  method using  the technique  you
> described.  Works well.  But since  there's  a  lot to  do in  my
> 'WriteStringOut'  I  thought,  it  would  be  better  to override
> 'Paint()'  and  replace  the  (inherited)  =Canvas=  there with a
> bitmap's canvas  so I could  do the painting  for the whole  page
> (not only  line by line)  an the memory-bitmap  and then 'Draw()'
> the  whole page  at once.  - Unfortunately  I failed.  There's no
> (working) 'Assign()'-method  for a Canvas.  So I wonder  if it is
> possible at all, what I tried to describe?

> MyControl.Paint;                { Save/replace inherited Canvas }
> |_
>   aControl.Paint;
>   |_
>     aControl.PrepareTheLine();           { used replaced canvas }
>     |_
>       MyControl.WriteStringOut();        { used replaced canvas }
>      _|
>    _|
>  _|
> |
> MyControl.Paint;       { restore inherited Canvas / Draw onto it }

>--
>        Matthias

Chris Hill
Chris...@aol.com

Other Threads