0

I have played with Delphi 11 + FMX and I'm trying to draw on a Trectangle but 'shape.repaint' clears the canvas. Is there a way to save the already drawn pattern on canvas and add something to it later?

I've used Lazarus before and in it onpaint doesn't clear the canvas.

procedure TForm2.Button1Click(Sender: TObject);
begin
    x:=random(100);

    rectangle1.Repaint;
end;

procedure TForm2.Rectangle1Paint(Sender: TObject; Canvas: TCanvas;
  const ARect: TRectF);
  var
  rect:TRectF;

begin

      rect:=TRectF.Create(100-x,100-x,100+x,100+x);
      canvas.Stroke.Color:=TAlphaColors.Black;
      canvas.DrawEllipse(rect,255);
end;
JJJ
  • 11
  • 3
  • 1
    I know almost nothing about FMX, but in VCL this simply isn't how you do things. You draw each frame at a time, completely. Nothing is saved automatically for the next frame. – Andreas Rejbrand May 12 '23 at 18:57
  • Thanks. I meant, like in the example former ellipse is deleted but I would like to keep the old pattern visible and paint over it. – JJJ May 13 '23 at 08:38
  • I think this works like in the VCL, so your approach is not sound. You need to draw the frame completely every time. Here's a VCL example that shows how you can use data structures to remember things between frames: https://stackoverflow.com/a/7224075/282848 – Andreas Rejbrand May 13 '23 at 09:20
  • 1
    @AndreasRejbrand is correct. You need to redraw everything every time. Repaint is just that: **Re**painting the canvas. The application itself will call the event if it deems that a repaint is necessary so you can never assume that anything you draw on the canvas will stay. It is designed such that you will redraw it all each time. – Philip J. Rayment May 13 '23 at 11:56
  • Why don't you draw on a bitmap? Then you can add to the drawing. In the OnPaint just draw the bitmap to screen. – Renate Schaaf May 13 '23 at 12:50
  • I would just use a TImage instead. A TImage already has its own TBitmap. You just need to draw when the image needs to change, so not in the paint event. Note also that you'll then need to use TImage.Bitmap.Canvas.BeginScene and TImage.Bitmap.Canvas.EndScene above and below your drawing commands. – XylemFlow May 15 '23 at 13:29

0 Answers0