Get the default value of a resource string? lazarus / 21-General ---------------------------------------------------------------------- CM630 · 2023-11-21 20:46 If I define: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i resourcestring  alabala = 'ala-bala'; is it possible to retireve the default value of the resource string („ala-bala“)? For example, the value might be changed to „алабала“ or whatever by LCLTranslator, but I need to get the default value. Is it possible to do it? ---------------------------------------------------------------------- PascalDragon · 2023-11-22 22:13 It isn't exactly documented (thus it could potentially change), but if you take a pointer to a resourcestring you in fact take a pointer to the CurrentValue field of a TResourceStringRecord. So you could essentially do this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program tresstr; {$mode objfpc}{$H+} resourcestring  TestStr = 'Hello World'; var  resstr: PResourceStringRecord;begin  Writeln(TestStr);  resstr := PResourceStringRecord(PPtrUInt(@TestStr) - 1);  Writeln(resstr^.Name);  Writeln(resstr^.CurrentValue);  Writeln(resstr^.DefaultValue);end. But again, this is an implementation detail, so use with care. ---------------------------------------------------------------------- jamie · 2023-11-22 22:30 How about this. Const Test = 'Some Text'; ResourceString  RTest = Test; Later you can compare Test with RTest.. just a thought and not sure if that will even work. ---------------------------------------------------------------------- CM630 · 2023-11-23 07:05 Quote from: PascalDragon on November 22, 2023, 11:13:45 pm It isn't exactly documented (thus it could potentially change), but if you take a pointer to a resourcestring you in fact take a pointer to the CurrentValue field of a TResourceStringRecord. So you could essentially do this: ... Thanks, that works! But how am I to use it in a function? The function below makes the app crash. I suppose I am doing something wrong with the input - aResString is not exactly a string. And yet there might be another problem - .DefaultValue is and AnsiString. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function ResStringDefault(aResString: string): string;var  resstr: PResourceStringRecord;begin  resstr := PResourceStringRecord(PPtrUInt(@aResString) - 1);  Result := resstr^.DefaultValue;end;   Quote from: jamie on November 22, 2023, 11:30:40 pmHow about this....I was thinking of storing the values of the resourcestrings before applying the PO localization, sounds like your proposal. ---------------------------------------------------------------------- TRon · 2023-11-23 07:43 Quote from: CM630 on November 23, 2023, 08:05:46 amThanks, that works! But how am I to use it in a function? The function below makes the app crash. At the least pass the string as a var ? ---------------------------------------------------------------------- CM630 · 2023-11-23 07:48 Quote from: TRon on November 23, 2023, 08:43:09 amAt the least pass the string as a var ? If you mean, function ResStringDefault(var aResString: string): string; I have already tried that. I get “Error: Variable identifier expected” when I call the function, possibly because a resstring is a const in a degree. ---------------------------------------------------------------------- TRon · 2023-11-23 07:53 Quote from: CM630 on November 23, 2023, 08:48:33 amIf you mean, function ResStringDefault(var aResString: string): string; I have already tried that. I get “Error: Variable identifier expected” when I call the function, possibly because a resstring is a const in a degree. Ah yes indeed. My bad. Sorry for that. In that case opt to pass the pointer to the string. A bit more inconvenient but should work. (*) edit: * Don't forget to remove the @ from the calculation in that case (as it is already a pointer to resstring then). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i resourcestring  TestStr = 'Hello World'; function ResStringDefault(aResString: pstring): string;var  resstr: PResourceStringRecord;begin  resstr := PResourceStringRecord(PPtrUInt(aResString) - 1);  Result := resstr^.DefaultValue;end;    ...  resstr1 := ResStringDefault(@teststr);  ... ---------------------------------------------------------------------- CM630 · 2023-11-23 11:17 Thanks, now it works! I hope that DefaultValue being an ansistring won't cause trouble. ---------------------------------------------------------------------- TRon · 2023-11-23 11:47 Quote from: CM630 on November 23, 2023, 12:17:23 pmI hope that DefaultValue being an ansistring won't cause trouble.[/size][/font] I assumed you was using ansistrings but you are correct. You can always refer to the correct type f.e. pansistring (and ansistring) instead. ---------------------------------------------------------------------- PascalDragon · 2023-11-25 17:09 Quote from: CM630 on November 23, 2023, 12:17:23 pmThanks, now it works! I hope that DefaultValue being an ansistring won't cause trouble. In main it's declared as RTLString, because the RTL can now be compiled with both String = AnsiString and String = UnicodeString and RTLString reflects that.