Managing Plugin Modules (Delphi)

Hydra provides several ways to load a plugin module; to load the module you always need a module manager. For VCL projects you can use the THYModuleManager component, and for FireMonkey the THYFMXModuleManager. Most of the methods work in a same way for both these components, so let's review these methods:

General

  • LoadModule(FileName, InNewAppDomain) - This method is suitable for loading all types of modules, it will automatically detect the module type and call the appropriate method. Please note that the second parameter, InNewAppDomain, affects how managed modules are loaded. By default this parameter is set to true, which means that every module will be loaded into a separate AppDomain. In VCL this method returns an index of the loaded module, in FireMonkey a reference to the module.
ModuleManager.LoadModule('MyModule.dll', false);
  • LoadModule(SearchPath, InNewAppDomain) - This method allows you to load multiple modules that match the specified search path. This methods has a couple of overloads:
    • LoadModule(array of string, InNewAppDomain)
    • LoadModule(TStrings, InNewAppDomain) - These two methods took the module file path from an array or list.
    • LoadModule(InNewAppDomain) - Loads the modules specified in the ModulesToLoad property of the module manager.
ModuleManager.LoadModules('`.dll', false);

ModuleManager.ModulesToLoad.Add('MyModule.dll');
ModuleManager.LoadModules;
  • AutoLoad property - Module manager can load modules automatically after its creation, to do this you first need to set a list of module file names in the ModulesToLoad property.

Specific

  • LoadUnmanagedModule(FileName) - Loads an unmanaged module by the specified path; please note that this method will work only on Delphi VCL modules.
  • LoadManagedModule(FileName, InNewAppDomain) - Loads a .NET module by the specified path, the InNewAppDomain parameter works in the same way as in the LoadModule method.
  • LoadFireMonkeyModule(FileName) - Allows to load a plugin module that was created with Delphi FireMonkey.
  • LoadSilverlightModule(FileName) - Allows you to load a Silverlight module. You need to provide a file name to the module's xap file.
ModuleManager.LoadManagedModule('Net.Plugin.dll', false);

ModuleManager.LoadSilverlightModule('MySilverlightPlugin.xap');

Unloading Modules

There is no need to manually unload modules since Hydra will do this automatically when the module manager is destroyed, however, module manager provides several methods to preform this task:

  • UnloadModules - Unloads all previously loaded modules.
  • UnloadModule(Index) - Allows you to unload a single module with a specified index.
    • UnloadModule(FileName) - Unloads a module by its file name.
    • ''UnloadModule(THYFMXModule) - FireMonkey only, allows you to unload a module by its reference.

Please note that you must release all plugin instances before you unload a module, or you will get an exception.