Dynamic Switching of Resource DLLs

From RAD Studio
Jump to: navigation, search

Go Up to Using Resource DLLs


In addition to locating a resource DLL at application startup, it is possible to switch resource DLLs dynamically at run time.

For example, the following code switches the interface language to French:

const
  FRENCH = (SUBLANG_FRENCH shl 10) or LANG_FRENCH;
if LoadNewResourceModule(FRENCH) <> 0 then
  ReinitializeForms;
const FRENCH = (SUBLANG_FRENCH << 10) | LANG_FRENCH;

if (LoadNewResourceModule(FRENCH))
    ReinitializeForms();

The advantage of this technique is that the current instance of the application and all of its forms are used. It is not necessary to update the registry settings and restart the application or re-acquire resources required by the application, such as logging in to database servers.

When you switch resource DLLs the properties specified in the new DLL overwrite the properties in the running instances of the forms.

Note: Any changes made to the form properties at run time will be lost. Once the new DLL is loaded, default values are not reset. Avoid code that assumes that the form objects are reinitialized to the their startup state, apart from differences due to localization.

See Also