This is all targeting .Net core, and I don’t envision targeting anything else.
What I’m trying to do is to mimic a very convenient construct found in Delphi. Basically, when one accesses a resourcestring
, the LoadResourceString
method is called to extract it from the resources and return a string
In our case, the LoadResourceString
method is hooked by the translation engine so that any resourcestring
is automatically translated when converted to string
.
However, as the current language may change during the life of the application, we often do not want the translation to happen immediately, but rather when the value is to be displayed to the user.
This is why we use the @RSTest
construct which gives us a pointer to the structure used internally to get the required parameters for the Win32 LoadString
API, that is a pointer to this record:
TResStringRec = packed record
// 32bit = 8 bytes
// 64bit = 16 bytes
Module: ^HMODULE;
Identifier: NativeUint;
end;
So, in thousands of places, we have the @RSTest
construct, we even build constants of PResStringRec
values like so:
const
MyEnumResourceStrings : array[TMyEnum] of PResStringRec = (@SFirstValue, @SSecondValue, @SThirdValue);
Once again, this allows deferring the actual conversion to string to the very latest moment, the one where it gets displayed to the user.
Now, I understand that pointers are not welcome in the .Net world, but I’d rather avoid IFDEFing thousands of places, along with loosing the deferred conversion ability. Hence the reason why I’m trying to store the pointer returned by @RSTest
so that I can reuse it later on. I don’t really care for the bytes inside the string, I would just use Tmp^
when the actual value is needed.
To implement this, I thought of declaring a record with an implicit operator converting from the value returned by @RSTest
, then with overriding the ^
operator but, if I can’t get the pointer type right, this is not going to be feasible.
I hope this clarifies what I’m trying to achieve.