Recent

Author Topic: [SOLVED] Visibility of resourcestring  (Read 844 times)

CM630

  • Hero Member
  • *****
  • Posts: 1447
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[SOLVED] Visibility of resourcestring
« on: November 18, 2023, 12:26:43 pm »
I am reading this:
https://wiki.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications

It is stated:
Quote
In a larger project, it is convenient to collect all resourcestrings in a separate unit; you can access the strings from other forms and units and avoid cross-referencing of units this way.


So I made a new project, enabled i18N.
The project has one main form, I created a unit named localize.

I added it in the Uses of the main form.
And when I did showmsg (lngOK) I get:
„Error: Identifier not found "lngOk"“  :o


What am I doing wrong?


Code: Pascal  [Select][+][-]
  1. unit localize;
  2.  
  3.  
  4.  
  5. {$mode ObjFPC}{$H+}
  6.  
  7.  
  8. interface
  9.  
  10.  
  11. uses
  12.   Classes, SysUtils;
  13.  
  14.  
  15. implementation
  16.  
  17.  
  18. resourcestring
  19.   lngOk = 'Okay';
  20.  
  21.  
  22. end.  


Code: Pascal  [Select][+][-]
  1. unit main;
  2.  
  3.  
  4.  
  5. {$mode objfpc}{$H+}
  6.  
  7.  
  8. interface
  9.  
  10.  
  11. uses
  12.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  13.   localize, LCLTranslator;
  14.  
  15.  
  16. type
  17.  
  18.  
  19.   { TForm1 }
  20.  
  21.  
  22.   TForm1 = class(TForm)
  23.     Button1: TButton;
  24.     procedure Button1Click(Sender: TObject);
  25.   private
  26.  
  27.  
  28.   public
  29.  
  30.  
  31.   end;
  32.  
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37.  
  38. implementation
  39.  
  40.  
  41. {$R *.lfm}
  42.  
  43.  
  44. { TForm1 }
  45.  
  46.  
  47. procedure TForm1.Button1Click(Sender: TObject);
  48. begin
  49.   ShowMessage (lngOk);
  50. end;
  51.  
  52.  
  53. end.
  54.  
« Last Edit: November 18, 2023, 02:12:03 pm by CM630 »
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

Paolo

  • Hero Member
  • *****
  • Posts: 589
Re: Visibility of resourcestring
« Reply #1 on: November 18, 2023, 01:07:19 pm »
Move the resourcestring in the interface section may help

CM630

  • Hero Member
  • *****
  • Posts: 1447
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Visibility of resourcestring
« Reply #2 on: November 18, 2023, 01:11:30 pm »
Moving to Interface results in
„Fatal: Syntax error, "IMPLEMENTATION" expected but "USES" found“

But moving after USES seems works!
Thanks!

WORKING
Code: Pascal  [Select][+][-]
  1. unit localize;
  2.  
  3.  
  4. {$mode ObjFPC}{$H+}
  5.  
  6.  
  7. interface
  8.  
  9.  
  10. uses
  11.   Classes, SysUtils;
  12.  
  13.  
  14. resourcestring
  15.   lngOk = 'Okay';
  16.  
  17.  
  18. implementation
  19.  
  20.  
  21. end.  
  22.  

NOT WORKING
Code: Pascal  [Select][+][-]
  1.  
  2. unit localize;
  3.  
  4.  
  5. {$mode ObjFPC}{$H+}
  6.  
  7.  
  8. interface
  9.  
  10.  
  11. resourcestring
  12.   lngOk = 'Okay';
  13.  
  14.  
  15. uses
  16.   Classes, SysUtils;
  17.  
  18.  
  19. implementation
  20.  
  21. end.  
« Last Edit: November 18, 2023, 01:14:13 pm by CM630 »
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

PascalDragon

  • Hero Member
  • *****
  • Posts: 6049
  • Compiler Developer
Re: Visibility of resourcestring
« Reply #3 on: November 19, 2023, 06:41:04 pm »
Moving to Interface results in
„Fatal: Syntax error, "IMPLEMENTATION" expected but "USES" found“

The whole area from interface up until implementation is the “interface section”. So if someone says “move xyz to the interface section” they'll mean to the syntatically correct place, in this case after the uses-clause of the interface section.

 

TinyPortal © 2005-2018