Separate module for closing TPageControl tabs lazarus / 61-Beginners ---------------------------------------------------------------------- BIT · 2021-09-14 06:10 Hello, can this code be saved in separate modules and used in the main form for the TPageControl component close tab icon. I do not know how to work with classes)) 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 unit PageControlButtonClose; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, ComCtrls, LCLType, Controls, types, Graphics, LCLIntf; type   { TPageControl }  TPageControl = class(ComCtrls.TPageControl)  private  const    btnSize = 14;   protected    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;      X, Y: integer); override;    procedure PaintWindow(DC: HDC); override;  end; implementation { TPageControl } procedure TPageControl.MouseDown(Button: TMouseButton; Shift: TShiftState;  X, Y: integer); var  R: TRect;begin  inherited MouseDown(Button, Shift, X, Y);  if Button = mbLeft then  begin    R := TabRect(ActivePageIndex);    if PtInRect(Classes.Rect(R.Right - btnSize - 5, R.Top + 4,      R.Right - 5, R.Top + btnSize + 4), Classes.Point(X, Y)) then    begin       ActivePage.Free;    end;   end;end; procedure TPageControl.PaintWindow(DC: HDC);var  i: integer;  R: TRect;  bm: TBitmap;begin  inherited PaintWindow(DC);   bm := TBitmap.Create;  try    bm.SetSize(16, 16);   Images.GetBitmap(0, bm);      for i := 0 to Pred(PageCount) do    begin      R := TabRect(i);      StretchBlt(DC, R.Right - btnSize - 4, R.Top + 2,        btnSize, btnSize, bm.Canvas.Handle, 0, 0, 16, 16, cmSrcCopy);    end;  finally    bm.Free;  end;end; end. ---------------------------------------------------------------------- BIT · 2021-09-14 07:02 This code does not work when connected to the main form from a separate module. If this code is inserted into the main form it works fine. The question is how to use this code from the plug-in in the main one? ---------------------------------------------------------------------- Awkward · 2021-09-14 07:54 Easy to use... LCL must be patched ^_^ ---------------------------------------------------------------------- zamtmn · 2021-09-14 09:06 This is a hack based on class substitution, it will not work in a separate module ---------------------------------------------------------------------- Zvoni · 2021-09-14 11:20 Why not write as a class helper? (instead of inheritance) ---------------------------------------------------------------------- korba812 · 2021-09-14 12:11 Quote from: Zvoni on September 14, 2021, 01:20:21 pmWhy not write as a class helper? (instead of inheritance) Because you can't override virtual methods this way. ---------------------------------------------------------------------- Zvoni · 2021-09-14 12:20 Quote from: korba812 on September 14, 2021, 02:11:04 pmQuote from: Zvoni on September 14, 2021, 01:20:21 pmWhy not write as a class helper? (instead of inheritance) Because you can't override virtual methods this way. https://wiki.freepascal.org/Helper_types#Method_hiding QuoteRestrictions A helper type may not     contain (class) destructors (except in trunk FPC 3.3.1)     contain class constructors (except in trunk FPC 3.3.1)     contain fields     contain abstract methods     "override" virtual methods of the extended class (they can be hidden by the helper though) Methods of the extended type can be overloaded (thus they are not hidden by the helper) by using the overload keyword. A call to Inherited MethodName should still work, or not? No, it doesn't, but the question remains: Does he even need to call the "Ancestor"-Method? ---------------------------------------------------------------------- BIT · 2021-09-14 12:21 Quote from: jamie on September 14, 2021, 01:17:26 pmQuote from: zamtmn on September 14, 2021, 11:06:31 amThis is a hack based on class substitution, it will not work in a separate module If you place the unit at the end or after the unit that houses the original class the compiler should see that one first in the local uses list. Thank you earned!