打印本文 打印本文 关闭窗口 关闭窗口
插件管理框架 for Delphi(二)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2490  更新时间:2009/4/23 18:35:09  文章录入:mintao  责任编辑:mintao
>       result := -1;   finally     UnLock;   end; end;   constructor TDllManager.Create; begin   FDllClass := TDll;   InitializeCriticalSection(FLock); end;   destructor TDllManager.Destroy; begin   DeleteCriticalSection(FLock);   inherited; end;   function TDllManager.GetDlls(const Index: Integer): TDll; begin   Lock;   try     if (Index >=0) and (Index <= Count - 1) then       result := Items[Index]     else       raise EDllError.CreateFmt(''''Error Index of GetDlls, Value: %d, Total Count: %d'''', [Index, Count]);   finally     UnLock;   end; end;   function TDllManager.GetDllsByName(const FileName: String): TDll; var   I: Integer; begin   Lock;   try     I := IndexOf(FileName);     if I >= 0 then       result := Dlls[I]     else       result := nil;   finally     UnLock;   end; end;   function TDllManager.IndexOf(const FileName: String): Integer; var   I: Integer; begin   result := -1;   Lock;   try     for I := 0 to Count - 1 do       if CompareText(FileName, Dlls[I].FileName) = 0 then       begin         result := I;         break;       end;   finally     UnLock;   end; end;   procedure TDllManager.Lock; begin   OutputDebugString(Pchar(''''TRLock DM'''' + IntToStr(GetCurrentThreadId) + '''':'''' + IntToStr(DWORD(Self))));   EnterCriticalSection(FLock);   OutputDebugString(Pchar(''''Locked DM'''' + IntToStr(GetCurrentThreadId) + '''':'''' + IntToStr(DWORD(Self)))); end;   procedure TDllManager.Notify(Ptr: Pointer; Action: TListNotification); begin   if Action = lnDeleted then   begin     //TDll(Ptr).OwnerSelf不同,则     //表明由 TDll.Destroy 触发;     if TDll(Ptr).Owner = Self then     begin       //防止FOwner设置为nil之后相关事件不能触发       TDll(Ptr).DoBeforeDllUnLoaded;       TDll(Ptr).FOwner := nil;       TDll(Ptr).Free;     end;   end   else   if Action = lnAdded then     TDll(Ptr).FOwner := Self;   inherited; end;   function TDllManager.Remove(const FileName: String): Integer; var   I: Integer; begin   result := -1;   Lock;   try     I := IndexOf(FileName);     if I >= 0 then       result := Remove(Dlls[I])     else       result := -1;   finally     UnLock;   end; end;   procedure TDllManager.UnLock; begin   LeaveCriticalSection(FLock);   OutputDebugString(Pchar(''''UnLock DM'''' + IntToStr(GetCurrentThreadId) + '''':'''' + IntToStr(DWORD(Self)))); end;   end.  

上一页  [1] [2] [3] 

打印本文 打印本文 关闭窗口 关闭窗口