PageRenderTime 23ms CodeModel.GetById 21ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/newStructBase/tangram framework/SysSvc.pas

https://github.com/qriver/Delphi2010
Pascal | 77 lines | 54 code | 14 blank | 9 comment | 5 complexity | 3b97834ed35b79d729e748bf1f0f0ecc MD5 | raw file
 1{------------------------------------
 2  ?????????
 3  ?????2008/11/09
 4  ???wzw
 5  ???wzw
 6-------------------------------------}
 7unit SysSvc;
 8
 9interface
10
11uses SysUtils,Windows,Classes,FactoryIntf;
12
13Type
14  TSysService=Class(TObject,IInterface)
15  private
16    FRefCount: Integer;
17  protected
18    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
19    function _AddRef: Integer; stdcall;
20    function _Release: Integer; stdcall;
21  public
22   // Constructor Create;
23   // Destructor Destroy;override;
24  end;
25
26  function SysService:IInterface;
27
28implementation
29
30uses SysFactoryMgr;
31
32var
33  FSysService:IInterface;
34
35function SysService:IInterface;
36begin
37  if not Assigned(FSysService) then
38    FSysService:=TSysService.Create;
39    
40  Result:=FSysService;
41end;
42
43{ TSysService }
44
45function TSysService._AddRef: Integer;
46begin
47  Result := InterlockedIncrement(FRefCount);
48end;
49
50function TSysService._Release: Integer;
51begin
52  Result := InterlockedDecrement(FRefCount);
53  if Result = 0 then
54    Destroy;
55end;
56
57function TSysService.QueryInterface(const IID: TGUID; out Obj): HResult;
58var aFactory:TFactory;
59begin
60  Result:=E_NOINTERFACE;
61  if self.GetInterface(IID,Obj) then
62    Result:=S_OK
63  else begin
64    aFactory:=FactoryManager.FindFactory(IID);
65    if Assigned(aFactory) then
66    begin
67      aFactory.CreateInstance(IID,Obj);
68      Result:=S_OK;
69    end;
70  end;
71end;
72
73initialization
74  FSysService:=nil;
75finalization
76  FSysService:=nil;
77end.