⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memman.pas

📁 Delphi高级开发指南是开发程序的好帮手
💻 PAS
字号:
unit MemMan;

interface

uses
  StdCtrls, Classes;

var
  AllocCount, FreeCount: Integer;
  AllocatedList: TList;

type
  TCountButton = class (TButton)
  protected
    class function NewInstance: TObject; override;
    procedure FreeInstance; override;
  end;

implementation

uses
  Windows, SysUtils;

class function TCountButton.NewInstance: TObject;
begin
  Inc (AllocCount);
  Result := inherited NewInstance;
  AllocatedList.Add (Result);
end;

procedure TCountButton.FreeInstance;
var
  nItem: Integer;
begin
  Inc (FreeCount);
  nItem := AllocatedList.IndexOf (self);
  AllocatedList.Delete (nItem);
  inherited FreeInstance;
end;

initialization
  AllocatedList := TList.Create;

finalization
  if (AllocCount - FreeCount) <> 0 then
    MessageBox (0, pChar (
      'Objects left: ' + IntToStr (AllocCount - FreeCount)),
      'MemManager', mb_ok);
  AllocatedList.Free;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -