Managing Plugin Modules (Delphi)
Hydra provides several ways to load a plugin module; to load the module you always need a module manager. Depending on used framework, it can be
- THYSimpleModuleManager - Module manager for console application. Works with plugins via cross-platform interfaces.
- THYModuleManager - Module manager for VCL hosts. works with plugins via IHYVCL* interfaces. requires runtime packages for using with VCL plugins
- THYVCLSimpleModuleManager - lightweigh version of module manager for VCL hosts. Works with plugins via crossplatform interfaces.
- THYFMXModuleManager - Module manager for VCL hosts. works with plugins via IHYFMX* interfaces. requires runtime packages for using with FMX plugins
Most of the methods work in a same way for each these components, so let's review these methods:
General
- LoadModule - 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, affects how managed modules are loaded.
ModuleManager.LoadModule('MyModule.dll', false);
-
LoadModules - These methods allows you to load multiple modules.
- LoadModules(aSearchPath, aDefaultDomain)
- LoadModules(aSearchPath, InNewAppDomain)
- LoadModules(array of string, aDefaultDomain)
- LoadModules(array of string, InNewAppDomain)
- LoadModules(TStrings, aDefaultDomain)
- LoadModules(TStrings, InNewAppDomain)
- LoadModules(aDefaultDomain)
- LoadModules(InNewAppDomain)
Two last methods loads 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
- LoadComModule(aGuid) - Loads COM plugin.
- LoadJavaModule(aFileName) - Loads Java module
- LoadManagedModule(aFileName, InNewAppDomain) - Loads a .NET module
- LoadManagedModule(aFileName, aDefaultDomain) - Loads a .NET module
- LoadSilverlightModule(aFileName) - Allows you to load a Silverlight module. You need to provide a file name to the module's
xap
file. - LoadUnmanagedCrossPlatformModule(aFileName) - Loads an unmanaged crossplatform module
- LoadUnmanagedModule(aFileName) - Loads an unmanaged [VCL or crossplatform] module. If module is VCL module, it load it as VCL module.
- LoadVCLModule(FileName) - Loads VCL module
- LoadFiremonkeyModule(FileName) - Loads an Firemonkey module
ModuleManager.LoadComModule('{7E47FB9E-8F3C-4F79-AA03-DB5A07033FE3}');
ModuleManager.LoadJavaModule('sample.nonvisual.plugin.jar');
ModuleManager.LoadManagedModule('Net.Plugin2.dll', hcdNewAppDomain);
ModuleManager.LoadManagedModule('Net.Plugin.dll', false);
ModuleManager.LoadSilverlightModule('MySilverlightPlugin.xap');
ModuleManager.LoadUnmanagedCrossPlatformModule('FMXPlugin.dll');
ModuleManager.LoadUnmanagedModule('VCLPlugin.dll');
ModuleManager.LoadVCLModule('VCLPlugin.dll');
ModuleManager.LoadFiremonkeyModule('FMXPlugin.dll');
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(aModule) - 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.