IResourceStrings.ValueByKey

Fore Syntax

ValueByKey(Key: Integer): String;

Fore.NET Syntax

ValueByKey[Key: uinteger]: string;

Parameters

Key. String key.

Description

The ValueByKey property determines a resource editor string, which key is passed by the Key parameter.

Comments

To set resource string by its identifier, use the IResourceStrings.Value property.

Fore Example

Executing the example requires that the repository contains resources with the APP_RESOURCE identifier. These resources contain default language as Russian and translation language as English.

Add links to the IO, Metabase system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    Resource: IResourceObject;
    ResStrs: IResourceStrings;
    ResStrKey: Integer;
    Locales: IResourceLocales;
    Locale: IResourceLocale;
Begin
    
// Get current repository
    mb := MetabaseClass.Active;
    
// Get resources
    Resource := mb.ItemById("APP_RESOURCE").Edit As IResourceObject;
    
// Get resource string elements
    ResStrs := Resource.Strings;
    
// Create a new string element
    ResStrKey := ResStrs.Add;
    
// Get resource languages collection
    Locales := Resource.Locales;
    
// Get default language
    Locale := Locales.DefaultLocale;
    
// Get string elements for default language
    ResStrs := Locale.Strings;
    
// Set string element value for default language
    ResStrs.ValueByKey(ResStrKey) := "Cancel";
    
// Get translation language
    Locale := Locales.CurrentLocale;
    
// Get string elements for translation language
    ResStrs := Locale.Strings;
    
// Set string element value for translation language
    ResStrs.ValueByKey(ResStrKey) := "Cancel";
    
// Save changes
    (Resource As IMetabaseObject).Save;
End Sub UserProc;

After executing the example a new string element is added to resources. Default language value and translation language value are set for it.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.ForeIO;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Resource: IResourceObject;
    ResStrs: IResourceStrings;
    ResStrKey: uinteger;
    Locales: IResourceLocales;
    Locale: IResourceLocale;
Begin
    // Get current repository
    mb := Params.Metabase;
    // Get resources
    Resource := mb.ItemById["APP_RESOURCE"].Edit() As IResourceObject;
    // Get resource string elements
    ResStrs := Resource.Strings;
    // Create a new string element
    ResStrKey := ResStrs.Add(0"");
    // Get resource languages collection
    Locales := Resource.Locales;
    // Get default language
    Locale := Locales.DefaultLocale;
    // Get string elements for default language
    ResStrs := Locale.Strings;
    // Set string element value for default language
    ResStrs.ValueByKey[ResStrKey] := "Cancel";
    // Get translation language
    Locale := Locales.CurrentLocale;
    // Get string elements for translation language
    ResStrs := Locale.Strings;
    // Set string element value for translation language
    ResStrs.ValueByKey[ResStrKey] := "Cancel";
    // Save changes
    (Resource As IMetabaseObject).Save();
End Sub;

See also:

IResourceStrings