How to get row table resource id from Delphi resource?

In Delphi, you can declare strings that will be stored in the string table of the module resource section.

resourcestring rsExample = 'Example'; 

At compile time, Delphi assigns an identifier to it and saves it in the row table.

Is there a way to get the id of a string declared as a resource?

The reason is because I use a package that works just like gnugettext. Some functions in System.pas (for example, LoadResString) are connected, so when I use resourcestring in the expression, it will be replaced with another line (translation). Of course, this is very convenient, but sometimes I need the original (untranslated) resource text.

When I can get the string resource identifier, I can call the LoadString API to get the source text instead of the translated text.

+6
source share
1 answer

To get the resource identifier of a resource, you can specify the address of the string in PResStringRec , then access the Identifier value.

Try this sample

 {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; resourcestring rsExample = 'Example'; begin try Writeln(rsExample); Writeln(PResStringRec(@rsExample)^.Identifier); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; readln; end. 
+10
source

Source: https://habr.com/ru/post/949568/


All Articles