用delphi 实现 singleton模式

下面是我今天写的singleton模式,请大家斧正。
PM表示ProgramManager,存放所谓全局变量(此例只有BoxTitle),和一些全局性的处理。

file://--------------------------------------------------------------------
unit uApplication;


interface


type
  TPM = class(TObject)
  private
    constructor Create;
  public
    destructor Destroy;override;
    class function GetSelf: TPM;

    对话框标题
    public BoxTitle:string;
  end;

implementation

var
    m_self:TPM;

constructor TPM.Create;
begin
end;

destructor TPM.Destroy;
begin
end;

class function TPM.GetSelf():TPM;
begin
    if m_self=nil then m_self:=TPM.Create;
    Result:=m_self;
end;


end.

调用程序
----------------------------------------
只要引用了此单元,在程序的任何一个地方,都可以如此访问
TPM.GetSelf().BoxTitle:="xxx 系统";

frmA.caption:=TPM.GetSelf().BoxTitle;

我不能确定的是,在implementation中定义的var m_self:TPM来代替c++中的static data member 是否合适。。。

转载于:https://www.cnblogs.com/zguosir/archive/2005/02/25/109256.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值