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.