IResourceStrings.ValueByKey

Syntax

ValueByKey(Key: Integer): 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.

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.

See also:

IResourceStrings