Load(Key: Integer; Stream: IIOStream): Boolean;
Load(Key: uinteger; Stream: Prognoz.Platform.Interop.ForeIO.IIOStream): boolean;
Key. Image key.
Stream. Stream.
The Load method loads an image with the specified resource key to stream.
If loading is successfully completed, the method returns True, otherwise it returns False.
Executing the example requires a form containing the ImageList component with the ImageList1 identifier. The component must contain an image used for icons of other form components. The form must contain connected resources containing a image with the ImgList identifier. Resources must contain two languages: Russian (default language) and English (translation language). The ImgList image must contain Russian and English language icons for form components.
Add links to the IO, Metabase system assemblies.
The procedure given as an example must be executed on occurring the OnCreate event for a form.
Sub TestFormOnCreate(Sender: Object; Args: IEventArgs);
Var
MB: IMetabase;
Resource: IResourceObject;
Locales: IResourceLocales;
Locale: IResourceLocale;
Binares: IResourceBinaries;
Stream: IIOStream;
BinKey: Integer;
Begin
// Get resources
Resource := Self.Resources;
// Get resource languages
Locales := Resource.Locales;
// Get current repository
MB := MetabaseClass.Active;
// Search in resources for the current repository language
Locale := Locales.FindByKey(MB.CurrentLocale);
// Get resource images for the current repository language
Binares := Locale.Binaries;
// Create a stream
Stream := New MemoryStream.Create;
// Get key for resource image for the current repository language
BinKey := Binares.FindById("ImgList");
// Load image with found key from resources
If Binares.Load(BinKey, Stream) Then
// Load image from the stream into the ImageList component
ImageList1.LoadFromStream(Stream);
End If;
End Sub TestFormOnCreate;
After executing the example icons used for form components depend on the current repository language.
The Fore.NET example differs from the Fore example because the ImageListNet component is under development for Fore.NET.
Executing the example requires that the repository contains resources with the APP_RESOURCE identifier containing the ImgList image. Resources must contain two languages: Russian (default language) and English (translation language). The ImgList image must contain Russian and English language options.
The file system must contain the image: C:\ResImg.png.
Imports Prognoz.Platform.Interop.ForeIO;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Resource: IResourceObject;
Locales: IResourceLocales;
Locale: IResourceLocale;
Binares: IResourceBinaries;
StreamR, StreamF: IIOStream;
BinKey: uinteger;
FileImg: IFileInfo;
BinW: IBinaryWriter;
Begin
// Get current repository
MB := Params.Metabase;
// Get resources
Resource := MB.ItemById["APP_RESOURCE"].Bind() As IResourceObject;
// Get resource languages
Locales := Resource.Locales;
// Search in resources for the current repository language
Locale := Locales.FindByKey(MB.CurrentLocale As uinteger);
// Get resource images for the current repository language
Binares := Locale.Binaries;
// Create a stream
StreamR := New MemoryStreamClass.Create();
// Get key for resource image for the current repository language
BinKey := Binares.FindById("ImgList");
// Load image with found key from resources
If Binares.Load(BinKey, StreamR) Then
FileImg := New FileInfoClass.Create();
FileImg.Attach("C:\ResImg.png");
BinW := FileImg.OpenBinaryWriter(True);
StreamF := BinW.Stream;
StreamF.CopyFrom(StreamR, StreamR.Size);
End If;
End Sub;
After executing the example the image that is saved for the current repository language is loaded from the resources to the file: C:\ResImg.png.
See also: