Гы... можно вот так считать количество созданных объектов(хотя есть и другие способы...), но все же приятно 
| Код | unit Unit10;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Types;
type TForm10 = class(TForm) procedure FormCreate(Sender: TObject); end;
TSomeObject = class(TObject) private {$J+} const C_ObjCount: Integer = 0; public constructor Create; destructor Destroy; override;
class function ObjCount: Integer; end;
var Form10: TForm10;
implementation
{$R *.dfm}
procedure TForm10.FormCreate(Sender: TObject); var i: Integer; lList: TList; begin ShowMessage(IntToStr(TSomeObject.ObjCount));
lList := TList.Create; try for i := 0 to 9 do lList.Add(TSomeObject.Create);
ShowMessage(IntToStr(TSomeObject.ObjCount));
for i := 0 to 9 do TObject(lList.Items[i]).Free;
lList.Clear; finally lList.Free; end;
ShowMessage(IntToStr(TSomeObject.ObjCount)); end;
{ TSomeObject }
constructor TSomeObject.Create; begin Inc(C_ObjCount); end;
destructor TSomeObject.Destroy; begin Dec(C_ObjCount); inherited; end;
class function TSomeObject.ObjCount: Integer; begin Result := C_ObjCount; end;
end.
|
|