Raoulw
Raoulw

Reputation: 23

Is it possible to change a resource string in Delphi when it is loaded from a resource DLL?

I have a Delphi app with localized resource DLLs.

I would like to do a search and replace on a resource string once it is loaded from the DLL.

Is there any internal procedure to hook into to do this?

I need a way to just do search and replace for any resource string loaded, and not just change a specific resource string.

Raoul.

Upvotes: 2

Views: 2162

Answers (1)

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43053

Yes you have to hook the LoadResString() procedure defined in System.pas.

See for instance how we do in http://synopse.info/fossil/finfo?name=SQLite3/SQLite3i18n.pas

There is everything in this unit code:

  • For extracting all resource strings (but you may also compile the executable with the "detailed map" option to get the same list);
  • For replacing all resource strings on the fly, to your expected language;
  • For caching all resource string, since default LoadResString API can be slow.

You have also similar code around, but this is one included in our Open Source mORMot framework, working from Delphi 6 up to XE2. There is also code to change on the fly all .dfm content (i.e. your forms), from the same translated text file. There is a chapter about that in the framework documentation at http://mormot.net

I think you will get here every code pattern needed for your task.

Upvotes: 6

Related Questions