IResourceBinaries.ValueByKey

Syntax

ValueByKey(Key: Integer): IIOStream;

Parameters

Key. Image key.

Description

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

Comments

To set resource image by its identifier, use the IResourceBinaries.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;
    Binares: IResourceBinaries;
    ResKey: Integer;
    Locales: IResourceLocales;
    Locale: IResourceLocale;
    FileImg: IFileInfo;
    BinR: IBinaryReader;
    Stream: IIOStream;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get resources
    Resource := mb.ItemById("APP_RESOURCE").Edit As IResourceObject;
    // Get images
    Binares := Resource.Binaries;
    // Create a new string element
    ResKey := Binares.Add;
    // Get resource languages collection
    Locales := Resource.Locales;
    // Get default language
    Locale := Locales.DefaultLocale;
    // Get images for default language
    Binares := Locale.Binaries;
    // Get file with new image for default language
    FileImg := New FileInfo.Attach("c:\ru.png");
    If FileImg.Exists Then
        BinR := FileImg.OpenBinaryReader;
        Stream := BinR.Stream;
        // Replace image for default language
        Binares.ValueByKey(ResKey) := Stream;
    End If;
    // Get the current translation language
    Locale := Locales.CurrentLocale;
    // Get string elements for translation language
    Binares := Locale.Binaries;
    // Get file with new image for translation language
    FileImg := New FileInfo.Attach("c:\en.png");
    If FileImg.Exists Then
        BinR := FileImg.OpenBinaryReader;
        Stream := BinR.Stream;
        // Replace image for translation language
        Binares.ValueByKey(ResKey) := Stream;
    End If;
    Dispose FileImg;
    // 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:

IResourceBinaries