Problem with drawing and deleting rectangle lazarus / 39-Graphics ---------------------------------------------------------------------- Tomi · 2024-11-06 14:32 Hello experts! I would like draw a rectangle on images in my program with DrawFocusRect() function, but something is wrong, because I can't delete the rectangle from its previous place when I have more than one images. These images are part of an own type: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type Ttiles = class(TCustomimage)  private  publicend; and a TScrollBox contains them (tilelist). I load these images as a follows in a mouse event of a button: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if (imageOpener.Execute) and (numbersourcetiles<255) thenbegin     sourcetileimg:=TPicture.Create;     sourcetileimg.LoadFromFile(imageOpener.FileName);     //     setlength(tile,numbersourcetiles+1);     tile[numbersourcetiles]:=Ttiles.Create(tilelist);     tile[numbersourcetiles].Parent:=tilelist;     tile[numbersourcetiles].OnMouseUp:=@srctileclick;     tile[numbersourcetiles].OnPaint:=@tilePaint;     if numbersourcetiles>0 then tile[numbersourcetiles].Top:=tile[numbersourc etiles-1].Top+tile[numbersourcetiles-1].height+2;     tile[numbersourcetiles].width:=sourcetileimg.width;     tile[numbersourcetiles].height:=sourcetileimg.height;     tile[number sourcetiles].canvas.copyrect(Rect(0,0,tile[numbersourcetiles].width,ti le[numbersourcetiles].height),sourcetileimg.bitmap.canvas,Rect(0,0,sou rcetileimg.width,sourcetileimg.height));     inc(numbersourcetiles);   freeandnil(sourcetileimg);end; This is the srctileclick function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.srctileclick(Sender: TObject;  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var i: byte;begin  if numbersourcetiles>0 then  begin    for i:=0 to numbersourcetiles-1 do    begin         if (X>=tile[i].Left) and (X<=tile[i].Left+tile[i].width) and ((ScreenToCl ient(mouse.cursorpos).Y+tilelist.VertScrollBar.Position)- tilelist.Top>=tile[i].Top) and ((ScreenToClient(mouse.cursorpos).Y+til elist.VertScrollBar.Position)- tilelist.Top<=tile[i].Top+tile[i].height) then         begin          if thereistiletoput=true then            begin                 FreeAndNil(tiletoput);                 thereistiletoput:=false;          end;            if (GetKeyState(VK_CONTROL) and $80)<>0 then //Assign tile to grid:            begin                 X:=tile[i].Scr eenToClient(mouse.cursorpos).X- (tile[i].ScreenToClient(mouse.cursorpos).X mod tilewidth);               Y:=tile[i].ScreenToClient(mouse.cursorpos).Y- (tile[i].ScreenToClient(mouse.cursorpos).Y mod tileheight);          end;            tilex:=X;            tiley:=Y;            tiletoput:=Tbitmap.Create;            tiletoput.width:=tilewidth;          tiletoput.height:=tileheight;            tiletoput.canvas.copyre ct(Rect(0,0,tilewidth,tileheight),tile[i].canvas,Rect(tilex,tiley,tile x+tilewidth,tiley+tileheight));            thereistiletoput:=true;          actualtileimage:=i;            tile[actualtileimage].invalidate;            Break;         end;    end;  end;end; And the tilePaint function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.tilePaint(Sender: TObject);var fromx,fromy: word;begin  if thereistiletoput=true then  begin     if (GetKeyState(VK_CONTROL) and $80)<>0 then     begin         fromx:=tilex-(tilex mod tilewidth);       fromy:=tiley-(tiley mod tileheight);     end     else     begin       fromx:=tilex;         fromy:=tiley;     end;     tile[actualtilei mage].canvas.drawfocusrect(Rect(fromx,fromy,fromx+tilewidth,fromy+tile height));  end;end; So, I would like put piece of images from an image onto the other's canvas and I would like make visual this piece for the user with this rectangle, but when I clicking the image, many rectangles remain on them. What should I do? Is it possible to delete those unnecessary rectangles?