Sign in Join
Wiki copytemporary

IDE Window: Make ResourceString

Deutsch · English · Français · 日本語

This wizard helps to convert a string constant into a resourcestring.

Place 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.

A string constant is for example 'Some text'.

Conversion Options

Identifier prefix

You 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.

Identifier length

This is the maximum length of the automatically created identifier.

Custom identifier

Instead of using an automatically created identifier, you can specify the identifier on your own here.

Resourcestring section

This 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.

String with same value

This 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.

Where to put the new identifier in the resourcestring section

If a new identifier is created, this defines where it will be added in the resourcestring section.

String constant in source

This shows the old or current source code.

Source preview

This 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.

Examples

Example 1: Setting the caption of a form

If 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:

pascal
 
  resourcestring
    rsSomeText = 'Some text';

Add in the FormCreate event the following line:

pascal
 
  Caption:='An example caption';

Place the cursor on the string constant, i.e. somewhere between the two '. Then do -> <Right click> Refactoring | Make Resource String

Set in the identifier prefix 'rs' without the '. The new automatically suggested identifier will be 'rsAnExampleCaption'. The preview shows

pascal
   Caption:=rsAnExampleCaption;
 --------------------------------------------------------------------------------
 rsAnExampleCaption = 'An example caption'

Click ok.

Example 2 : Complex string constants

When converting a complex string expression with variables and functions, the tool will use the Format function. For instance the statement:

pascal
 
  Caption:='Left='+IntToStr(Left)+' Top='+IntToStr(Top);

will be replaced with

pascal
 
  Caption:=Format(rsLeftTop, [IntToStr(Left), IntToStr(Top)]);

and the new resourcestring will be

pascal
 
  rsLeftTop = 'Left=%s Top=%s'

The Format function is defined in the SysUtils unit. If your unit uses section does not already contain it, you must add it yourself.

See also


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.

Revision 3, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.