📄 countf.pas
字号:
unit CountF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Menus;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCountButton = class (TButton)
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
class function GetTotal: Integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
TotBtns: Integer = 0;
constructor TCountButton.Create (AOwner: TComponent);
begin
inherited;
Inc (TotBtns);
end;
destructor TCountButton.Destroy;
begin
Dec (TotBtns);
inherited Destroy;
end;
class function TCountButton.GetTotal: Integer;
begin
Result := TotBtns;
end;
procedure TForm1.FormMouseDown(
Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with TCountButton.Create (self) do
begin
Parent := self;
Left := X;
Top := Y;
Width := Width + 60;
Caption := Format ('%d Button at %d, %d',
[GetTotal, X, Y]);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Caption := Format ('CountObj: %d custom buttons',
[TCountButton.GetTotal]);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MessageBox (0, PChar (Format (
'There are %d CountButton objects',
[TCountButton.GetTotal])),
'Destroy', mb_OK);
end;
initialization
MessageBox (0, PChar (Format (
'There are %d CountButton objects',
[TCountButton.GetTotal])),
'Initialization', mb_OK);
finalization
MessageBox (0, PChar (Format (
'There are %d CountButton objects',
[TCountButton.GetTotal])),
'Finalization', mb_OK);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -