ValueByKey(Key: Integer): IIOStream;
ValueByKey[Key: uinteger]: Prognoz.Platform.Interop.ForeIO.IIOStream;
Key. Image key.
The ValueByKey property determines a resource editor image, which key is passed by the Key parameter.
To set resource image by its identifier, use the IResourceBinaries.Value property.
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.
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;
Binares: IResourceBinaries;
ResKey: uinteger;
Locales: IResourceLocales;
Locale: IResourceLocale;
FileImg: IFileInfo;
BinR: IBinaryReader;
Stream: IIOStream;
Begin
// Get current repository
mb := Params.Metabase;
// Get resources
Resource := mb.ItemById["APP_RESOURCE"].Edit() As IResourceObject;
// Get images
Binares := Resource.Binaries;
// Create a new string element
ResKey := Binares.Add(0, "");
// 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 FileInfoClass.Create();
FileImg.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 FileInfoClass.Create();
FileImg.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;
// Save changes
(Resource As IMetabaseObject).Save();
End Sub;
See also: