// // 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. // #include #pragma hdrstop #include "%ModuleIdent.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" T%FormIdent *%FormIdent; //--------------------------------------------------------------------------- __fastcall T%FormIdent::T%FormIdent(TComponent* Owner) : TDataModule(Owner) { } bool RegisterLibrary() // // 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 // { return true; } bool UnRegisterLibrary() // // 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 // { return true; } TEasyFactoryManager* FindFactoryManager(TDataModule* DataModule) { if (DataModule) { for (int i = 0; i < DataModule->ComponentCount; ++i) { if (dynamic_cast(DataModule->Components[i])) return dynamic_cast(DataModule->Components[i]); } } return NULL; } void 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 // { // Create the DataModule if necessary if (!%FormIdent) %FormIdent = new T%FormIdent(NULL); // Assign the FactoryManager if necessary if (!FactoryManager) { FactoryManager = FindFactoryManager(%FormIdent); for (int i = 0; i < %FormIdent->ComponentCount; ++i) { if (!dynamic_cast(%FormIdent->Components[i]) && dynamic_cast(%FormIdent->Components[i])) FactoryManager->ShellHandlerList->Add(%FormIdent->Components[i]); } } } void 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 // { // Factory Manager is a component in the DataModule so the DataModule will free it FactoryManager = NULL; delete %FormIdent; %FormIdent = NULL; }