unit %ModuleIdent; // // This unit contains the Design Time DataModule for the EasyNSE. It is created automaticlly // when a new EasyNSE project is created. Simply add your shell components from the EasyNSE // tab in the toolbar and design as you would a normal form. There are a few things to remember though. // // 1) If you change the names of the DataModule or the Factory Manager you must // reflect those changes in the function InitializeLibrary below manually. // // 2) Do not add more TEasyFactoryManager objects to the DataModule. // // 3) As Explorer (or other applications that use the shell interfaces) calls to obtain an // interface EasyNSE will create a new copy if the object that implements that particular // handler. // // 4) Be Careful with global resources. There can be numerous objects for a handler created and active // at the same time that are in different threads. // // 5) Be Careful as the objects could also be in different processes so any global variables will // need to be reinitialized when the DLL is loaded in a new process. // // 6) DO NOT ACCESS components directly from the DataModule. EasyNSE creates clones of the components // on the data module for each call Explorer makes to the DLL asking for an object. This allows // for independent thread safe object. When an event is called the component is passed in the // Sender parameter for the event. USE THIS PARAMETER and not the component on the DataModule. // It will be the correct instance of the component object. Also be aware there may be other // objects of the same type that are in different treads so be cautions about thread safety as // the event handler may be interuptted in one thread and started in another on the same event. // Use thread syncronication objects such as critical sections to block threads until the current // thread is finished. Some objects have built in critical sections for your use such as the // TDataContainer and the BandForms. They have Lock and Unlock methods for general purpose use. interface {$include Compilers.Inc} uses SysUtils, Classes, Windows, {$IFNDEF COMPILER_6_UP} Forms, {$ENDIF} EasyIDEComponents; type T%FormIdent= class(T%AncestorIdent) private { Private declarations } public { Public declarations } end; procedure InitializeLibrary; procedure FinalizeLibrary; function RegisterLibrary: Boolean; function UnRegisterLibrary: Boolean; var %FormIdent: T%FormIdent; implementation {$R *.dfm} function RegisterLibrary: Boolean; // // Called when the DLL is registered as a COM Server with RegSvr32.exe // Return: // Return false if the library should not be registered as a COM Server // begin Result := True; end; function UnRegisterLibrary: Boolean; // // Called when the DLL is begin un-registered as a COM Server with RegSvr32.exe // Return: // Return false if the library should not be un-registered as a COM Server // begin Result := True; end; procedure InitializeLibrary; // // Called when the library is loaded into a processes memory space or when the // library is loaded for any reason to create the objects to implement the shell // handler or NSE. // // Notes: // Keep any code in this function to a minimum. Do not do any thing that would // cause other DLL's to be loaded within this function // function FindFactoryManager(DataModule: TDataModule): TEasyFactoryManager; var i: Integer; begin Result := nil; if Assigned(DataModule) then begin for i := 0 to DataModule.ComponentCount - 1 do begin if DataModule.Components[i] is TEasyFactoryManager then Result := DataModule.Components[i] as TEasyFactoryManager end end end; var i: Integer; begin // Create the DataModule if necessary if not Assigned(%FormIdent) then %FormIdent := T%FormIdent.Create(nil); // Assign the FactoryManager if necessary if not Assigned(FactoryManager) then begin FactoryManager := FindFactoryManager(%FormIdent); for i := 0 to %FormIdent.ComponentCount - 1 do begin if not( %FormIdent.Components[i] is TEasyFactoryManager) and (%FormIdent.Components[i] is TEasyRegisterableShellComponent) then FactoryManager.ShellHandlerList.Add(%FormIdent.Components[i]) end end end; procedure FinalizeLibrary; // // Called when the library is freed from a processes memory space or when the library // is being released // // Notes: // Keep any code in this function to a minimum. Do not do any thing that would // cause other DLL's to be loaded within this function // begin // Factory Manager is a component in the DataModule so the DataModule will free it FactoryManager := nil; FreeAndNil(%FormIdent); end; end.