LoadFromStream(Stream: IIOStream);
Stream. Stream.
The LoadFromStream method loads the context from specified stream.
To load the context to the stream use the ILanerContext.SaveToStream method.
Executing the example requires a form with the following components: the Button component named Button1, the LanerBox component named LanerBox1, and the UiErAnalyzer component named UiErAnalyzer1. UiErAnalyzer1 is a data source for LanerBox1. A working area of the time series database should be loaded to UiErAnalyzer1.
The document with the OBJ_CONTEXT identifier, that contains the saved context, must be present in repository.
The example is a handler of the OnClick event for the Button1 component.
Add links to the Express, ExtCtrls, Fore, Forms, Io, Laner, Metabase, and Tab system assemblies.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Mb: IMetabase;
pContext: ILanerContext;
ContextObject, LanerObject: IMetabaseObjectDescriptor;
Stream: IIOStream;
Laner: ILaner;
Doc: IDocument;
MemStream: IMemoryStream;
Begin
Mb := MetabaseClass.Active;
// Create a context
pContext := New LanerContext.Create;
// Load context from stream
ContextObject := Mb.ItemById("OBJ_CONTEXT");
Doc := ContextObject.Edit As IDocument;
Stream := Doc.GetAsStream;
pContext.LoadFromStream(Stream);
// Start of loading workbooks to context
pContext.BeginLoad;
// Load the first workbook
Laner := UiErAnalyzer1.ErAnalyzer.Laner;
If Not Laner.IsInContext Then
pContext.Register(Laner);
End If;
// Load workbooks, on which the first workbook depends
For Each LanerObject In Laner.Dependencies Do
Laner := LanerObject.Bind As ILaner;
If Not Laner.IsInContext Then
pContext.Register(Laner);
End If;
End For;
// Load workbooks that depend on the first workbook
For Each LanerObject In Laner.Dependents Do
Laner := LanerObject.Bind As ILaner;
If Not Laner.IsInContext Then
pContext.Register(Laner);
End If;
End For;
// End of loading workbooks to context
pContext.EndLoad;
// Save context to stream
MemStream := New MemoryStream.Create;
pContext.SaveToStream(MemStream);
Doc.LoadFromStream(MemStream);
(Doc As IMetabaseObject).Save;
End Sub Button1OnClick;
After executing the example the context is loaded from the OBJ_CONTEXT document. After that the workbook, all the dependant books and the books the workbook depends on are added to the context. The resulting context is saved to the OBJ_CONTEXT document.
See also: