ViaThinkSoft CodeLib
This article is in:
CodeLib → Programming aids → Delphi
Beginning with Delphi 12, the translation manager and resource DLL expert is not part of the IDE anymore. You can install it via GetIt package manager (VCL Translation Support).
This code helps switching the language at runtime.
This code helps switching the language at runtime.
procedure SwitchLanguage(newLang: string);
var
oldHInst: hInst;
newHInst: hInst;
bakOverride: string;
FileName: array [0..MAX_PATH] of Char;
Module: PLibModule;
begin
Module := LibModuleList;
GetModuleFileName(Module.Instance, FileName, Length(FileName));
bakOverride := GetLocaleOverride('');
try
SetLocaleOverride(newLang);
// Note: SetLocaleOverride() alone does not work, because LibModuleList.ResInstance
// is already set and won't be re-set by the FindResourceHInstance()!
newHInst := LoadResourceModule(FileName);
if newHInst = 0 then newHInst := Module.Instance;
oldHInst := Module.ResInstance;
Module.ResInstance := newHInst;
FreeLibrary(oldHInst);
except
SetLocaleOverride(bakOverride);
end;
end;
Daniel Marschall
ViaThinkSoft Co-Founder
ViaThinkSoft Co-Founder