Sign in Join
Wiki copytemporary

IDE Window: Make ResourceString: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11This wizard helps to convert a string constant into a resourcestring.
22
33Place the cursor on a string constant or select the part of the constant that should be converted. Then do \<Right click\> Refactoring \| Make Resource String.
44
55A string constant is for example 'Some text'.
66
77## Conversion Options
88
99### Identifier prefix
1010
1111You can create automatically a new identifier. The new identifier will start with the prefix, followed by the words of the string constant. If there is already a resourcestring with this value, the old identifier will be suggested. The IDE remembers the prefixes for each unit, so the last used prefix for the current unit is preselected first.
1212
1313### Identifier length
1414
1515This is the maximum length of the automatically created identifier.
1616
1717### Custom identifier
1818
1919Instead of using an automatically created identifier, you can specify the identifier on your own here.
2020
2121### Resourcestring section
2222
2323This combobox contains all available resourcestring sections of all units in scope. That means all sections of the current unit plus all sections in the interface parts of all used units.
2424
2525### String with same value
2626
2727This combobox contains all resourcestring identifiers with the same value as the new resourcestring. You can choose here, if you want to take one of them.
2828
2929### Where to put the new identifier in the resourcestring section
3030
3131If a new identifier is created, this defines where it will be added in the resourcestring section.
3232
3333- Append to section - add the new identifier at the end of the section.
3434- Insert alphabetically - insert the identifier alphabetically.
3535- Insert context sensitive - search the code above and below the current code position and search for resourcestring identifiers. If it finds one, then the new identifier is added there, otherwise it is appended at the end of the section.
3636
3737## String constant in source
3838
3939This shows the old or current source code.
4040
4141## Source preview
4242
4343This is a preview, how the string constant is replaced, followed by a line of dashes and then a preview of how the resourcestring will look like.
4444
4545## Examples
4646
4747### Example 1: Setting the caption of a form
4848
4949If you do not have already a resource string section, start one in the interface part of the unit. For example right above the 'implementation' keyword:
5050
5151``` pascal
5252
5353 resourcestring
5454 rsSomeText = 'Some text';
5555```
5656
5757Add in the FormCreate event the following line:
5858
5959``` pascal
6060
6161 Caption:='An example caption';
6262```
6363
6464Place the cursor on the string constant, i.e. somewhere between the two '. Then do -\> \<Right click\> Refactoring \| Make Resource String
6565
6666Set in the identifier prefix 'rs' without the '. The new automatically suggested identifier will be 'rsAnExampleCaption'. The preview shows
6767
68-`   Caption:=rsAnExampleCaption;`\
69-` --------------------------------------------------------------------------------`\
70-` rsAnExampleCaption = 'An example caption'   `
68+``` pascal
69+ Caption:=rsAnExampleCaption;
70+ --------------------------------------------------------------------------------
71+ rsAnExampleCaption = 'An example caption'
72+```
7173
7274Click ok.
7375
7476### Example 2 : Complex string constants
7577
7678When converting a complex string expression with variables and functions, the tool will use the **Format** function. For instance the statement:
7779
7880``` pascal
7981
8082 Caption:='Left='+IntToStr(Left)+' Top='+IntToStr(Top);
8183```
8284
8385will be replaced with
8486
8587``` pascal
8688
8789 Caption:=Format(rsLeftTop, [IntToStr(Left), IntToStr(Top)]);
8890```
8991
9092and the new resourcestring will be
9193
9294``` pascal
9395
9496 rsLeftTop = 'Left=%s Top=%s'
9597```
9698
9799The Format function is defined in the SysUtils unit. If your unit uses section does not already contain it, you must add it yourself.
98100
99101## See also
100102
101103- [[Getting translation strings right]]
102104
103105---
104106*From the Free Pascal wiki, page "IDE Window: Make ResourceString", as it stood on 2021-10-11 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history