Forum > Beginners

Separate module for closing TPageControl tabs

(1/2) > >>

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.

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?

Easy to use... LCL must be patched ^_^

This is a hack based on class substitution, it will not work in a separate module


--- Quote from: zamtmn on September 14, 2021, 11:06:31 am ---This is a hack based on class substitution, it will not work in a separate module

--- End quote ---

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.


[0] Message Index

[#] Next page

Go to full version