RAD Studio |  |

Dynamic Switching of Resource DLLs
See Also
Collapse All

In addition to locating a resource DLL at application startup, it is possible to switch resource DLLs dynamically at runtime. To add this functionality to your own applications, you need to include the ReInit unit in your uses statement. (ReInit is located in the Richedit sample in the Demos directory.) To switch languages, you should call LoadResourceModule, passing the LCID for the new language, and then call ReinitializeForms.

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

Copy Code

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

Copy Code

    const  FRENCH = MAKELANGID(SUBLANG_FRENCH, 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 runtime 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

Creating Resource DLLs

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!