请帮忙读一段100行左右的dx代码 ( 积分: 100 )

  • 主题发起人 主题发起人 autumn
  • 开始时间 开始时间
A

autumn

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
  TdxDBGridPopupMenuManager = class
  private
    GridHeaderPopupMenu: TdxDBGridHeaderPopupMenu;
    GridFooterPopupMenu: TdxDBGridFooterPopupMenu;
  protected
    constructor CreateInstance;
    class function AccessInstance(Request: Integer): TdxDBGridPopupMenuManager;
  public
    constructor Create;
    destructor Destroy
override;
    class function Instance: TdxDBGridPopupMenuManager;
    class procedure ReleaseInstance;
    function ShowGridPopupMenu(Grid: TdxDBGrid): Boolean;
  end;

。。。
{TdxDBGridPopupMenuManager}
class function TdxDBGridPopupMenuManager.AccessInstance(Request: Integer): TdxDBGridPopupMenuManager;
var FInstance: TdxDBGridPopupMenuManager;
begin
  FInstance := nil;
  case Request of
    0 : ;
    1 : if not Assigned(FInstance) then FInstance := CreateInstance;
    2 : FInstance := nil;
  else
    raise Exception.CreateFmt('Illegal request %d in AccessInstance',
      [Request]);
  end;
  Result := FInstance;
end;

constructor TdxDBGridPopupMenuManager.Create;
begin
  inherited Create;
  raise Exception.CreateFmt('Access class %s through Instance only',
    [ClassName]);
end;

constructor TdxDBGridPopupMenuManager.CreateInstance;
begin
  inherited Create;
  GridHeaderPopupMenu := TdxDBGridHeaderPopupMenu.Create;
  GridFooterPopupMenu := TdxDBGridFooterPopupMenu.Create;
end;

destructor TdxDBGridPopupMenuManager.Destroy;
begin
  if AccessInstance(0) = Self then AccessInstance(2);
  GridHeaderPopupMenu.Free;
  GridFooterPopupMenu.Free;

  inherited Destroy;
end;

class function TdxDBGridPopupMenuManager.Instance: TdxDBGridPopupMenuManager;
begin
  Result := AccessInstance(1);
end;

class procedure TdxDBGridPopupMenuManager.ReleaseInstance;
begin
  AccessInstance(0).Free;
end;
。。。

initialization

finalization
  TdxDBGridPopupMenuManager.ReleaseInstance;
  
end.
 
代码:
  TdxDBGridPopupMenuManager = class
  private
    GridHeaderPopupMenu: TdxDBGridHeaderPopupMenu;
    GridFooterPopupMenu: TdxDBGridFooterPopupMenu;
  protected
    constructor CreateInstance;
    class function AccessInstance(Request: Integer): TdxDBGridPopupMenuManager;
  public
    constructor Create;
    destructor Destroy
override;
    class function Instance: TdxDBGridPopupMenuManager;
    class procedure ReleaseInstance;
    function ShowGridPopupMenu(Grid: TdxDBGrid): Boolean;
  end;

。。。
{TdxDBGridPopupMenuManager}
class function TdxDBGridPopupMenuManager.AccessInstance(Request: Integer): TdxDBGridPopupMenuManager;
var FInstance: TdxDBGridPopupMenuManager;
begin
  FInstance := nil;
  case Request of
    0 : ;
    1 : if not Assigned(FInstance) then FInstance := CreateInstance;
    2 : FInstance := nil;
  else
    raise Exception.CreateFmt('Illegal request %d in AccessInstance',
      [Request]);
  end;
  Result := FInstance;
end;

constructor TdxDBGridPopupMenuManager.Create;
begin
  inherited Create;
  raise Exception.CreateFmt('Access class %s through Instance only',
    [ClassName]);
end;

constructor TdxDBGridPopupMenuManager.CreateInstance;
begin
  inherited Create;
  GridHeaderPopupMenu := TdxDBGridHeaderPopupMenu.Create;
  GridFooterPopupMenu := TdxDBGridFooterPopupMenu.Create;
end;

destructor TdxDBGridPopupMenuManager.Destroy;
begin
  if AccessInstance(0) = Self then AccessInstance(2);
  GridHeaderPopupMenu.Free;
  GridFooterPopupMenu.Free;

  inherited Destroy;
end;

class function TdxDBGridPopupMenuManager.Instance: TdxDBGridPopupMenuManager;
begin
  Result := AccessInstance(1);
end;

class procedure TdxDBGridPopupMenuManager.ReleaseInstance;
begin
  AccessInstance(0).Free;
end;
。。。

initialization

finalization
  TdxDBGridPopupMenuManager.ReleaseInstance;
  
end.
 
class function TdxDBGridPopupMenuManager.AccessInstance(Request: Integer): TdxDBGridPopupMenuManager;
var FInstance: TdxDBGridPopupMenuManager;
begin
FInstance := nil;
case Request of
0 : ;
1 : if not Assigned(FInstance) then FInstance := CreateInstance;
2 : FInstance := nil;
else
raise Exception.CreateFmt('Illegal request %d in AccessInstance',
[Request]);
end;
Result := FInstance;
end;

我想应该是实现单实例的意思,但这段不是很明白,请指教
 
除了Request=2时返回一个已有的实例(或新建一个)之外,其它时候返回Nil.
 
yayongm:request=2 返回nil啵
 

Similar threads

I
回复
0
查看
612
import
I
I
回复
0
查看
565
import
I
I
回复
0
查看
695
import
I
后退
顶部