Delphi 10.4 localization issues

Viewed 286

I'm trying Delphi 10.4. Localizing Windows applications was working like a charm in the past, but now when I dynamically load the RC DLL file, it only changes RCDATA, and not the "String Table" any more.

I was using this code (as quick resume)

NewInst := LoadLibraryEx(FileName, 0, LOAD_LIBRARY_AS_DATAFILE); 
....
CurModule.ResInstance := NewInstance;

FileName is the DLL file that has the resources (RCDATA and "String Table") that I could edit with "Resource Hacker" software, and can see that it contains "String table" Inside as expected.

It works fine for RCDATA (all forms are getting translated) but not "String table" anymore that is contained into Resourcestring section of any .pas file, and all string remains in the original language.

It was working fine in previous Delphi version (like 10.2) and I do not know why it fails with this version.

2 Answers

Core problem The problem is that resourcestrings are cached now, and you do not have access to clear the cache after you loaded new resource data :(

See https://quality.embarcadero.com/browse/RSP-30853 (and drop a vote if you think it has to be fixed)

Work-around I "Cloned" the resourcestring caching mechanism into a separate unit and re-routed LoadResStringFunc to my cloned unit. Here I allow access to the resstringcache, and thus can clear it after loading the new resource.

There is another solution. Disable the new caching by assigning LoadResStringFunc to nil. A good place to do that is in the beginning of the program.

begin
>>> ADD THIS to disable the caching
  LoadResStringFunc := nil;
>>>
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
Related