Recent

Author Topic: How to use area as resourcestrings  (Read 1547 times)

Zirneklitis

  • New Member
  • *
  • Posts: 15
How to use area as resourcestrings
« on: January 15, 2018, 12:25:29 pm »
Hi,

Is it possible to use an area as  “resourcestring”-s? E.g. I have:
Code: Pascal  [Select][+][-]
  1. resourcestring
  2.   HKey01 = 'Be patient!';
  3.   HKey02 = 'Any interactive changes are carried out within 1 second interval.';
  4.   HKey03 = '[Space], Mouse click - start/stop the timer.';

I want it to rewrite as:
Code: Pascal  [Select][+][-]
  1. resourcestring
  2.   HKey[1] = 'Be patient!';
  3.   HKey[2] = 'Any interactive changes are carried out within 1 second interval.';
  4.   HKey[3] = '[Space], Mouse click - start/stop the timer.';


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to use area as resourcestrings
« Reply #1 on: January 15, 2018, 01:21:14 pm »
AFAIK only by doing it the wasteful duplication way:
Code: Pascal  [Select][+][-]
  1. program ArrayOfResourcestring;
  2.  
  3. {$Mode objfpc}{$H+}
  4.  
  5. uses sysutils;
  6.  
  7. resourcestring
  8.    HKey00 = 'Be patient!';
  9.    HKey01 = 'Any interactive changes are carried out within 1 second interval.';
  10.    HKey02 = '[Space], Mouse click - start/stop the timer.';
  11.  
  12. var
  13.   HKey: TStringArray;
  14.   s: String;
  15.  
  16. begin
  17.   SetLength(HKey, 3);
  18.   HKey[0]:=HKey00;
  19.   HKey[1]:=HKey01;
  20.   HKey[2]:=HKey02;
  21.   for s in HKey do
  22.     WriteLn('"',s,'"');
  23.   WriteLn('Press [Enter]');
  24.   ReadLn;
  25. end.

Thaddy

  • Hero Member
  • *****
  • Posts: 14374
  • Sensorship about opinions does not belong here.
Re: How to use area as resourcestrings
« Reply #2 on: January 15, 2018, 02:58:52 pm »
But the notation can be slightly shorter:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2. uses sysutils;
  3.  
  4. resourcestring
  5.    HKey00 = 'Be patient!';
  6.    HKey01 = 'Any interactive changes are carried out within 1 second interval.';
  7.    HKey02 = '[Space], Mouse click - start/stop the timer.';
  8. var
  9.   HKey: TStringArray;
  10.   s:string;
  11. begin
  12.   HKey := TStringArray.Create(HKey00,HKey01,HKey02);
  13.   for s in HKey do
  14.     WriteLn('"',s,'"');
  15.   WriteLn('Press [Enter]');
  16.   ReadLn;
  17. end.

Or in trunk:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2. uses sysutils;
  3.  
  4. resourcestring
  5.    HKey00 = 'Be patient!';
  6.    HKey01 = 'Any interactive changes are carried out within 1 second interval.';
  7.    HKey02 = '[Space], Mouse click - start/stop the timer.';
  8. var
  9.   HKey: TStringArray;
  10.   s:string;
  11. begin
  12.   HKey := [HKey00,HKey01,HKey02];
  13.   for s in HKey do
  14.     WriteLn('"',s,'"');
  15.   WriteLn('Press [Enter]');
  16.   ReadLn;
  17. end.


Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Zirneklitis

  • New Member
  • *
  • Posts: 15
Re: How to use area as resourcestrings
« Reply #3 on: January 15, 2018, 04:41:55 pm »
Thank You! Thaddy's examples looks great for me. I hope the compiler will be in the same opinion   ;)

 

TinyPortal © 2005-2018