unit1.pas
来自「设计模式的源代码 Singleton模式」· PAS 代码 · 共 74 行
PAS
74 行
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses SingletonUnit2, SingletonUnit1;
var
aSingle: TSingletonl;
acSingle: TSingletonl;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
aSingle := TSingletonl.Create;
Label1.Caption := IntToStr(Glob_Singletonlist.Count);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
acSingle := TChildSingletonl.Create;
Label1.Caption := IntToStr(Glob_Singletonlist.Count);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if aSingle <> nil then
begin
aSingle.Destroy;
aSingle := nil;
end;
Label1.Caption := IntToStr(Glob_Singletonlist.Count);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if acSingle <> nil then
begin
acSingle.Destroy;
acSingle := nil;
end;
Label1.Caption := IntToStr(Glob_Singletonlist.Count);
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?