Specialized kind of IStream for objects.
When implementing your own objects, you will sometimes need to provide support for persistence. For example, with a custom feature renderer, persistence enables its settings to be written to an MXD file so that when ArcMap is restarted, the layer having custom rendering will be drawn in the same way as previously drawn. The COM concept of streams provides a way of reading and writing data to the persisted storage.
The ObjectStream is designed to allow you to correctly persist collections of ArcObjects objects in which there may be multiple references to a single object. For example if you persist both a Map and a LegendItem to the same stream, both may have references to a single layer. The ObjectStream ensures that the layer is only written to the persistence stream once. If you persist objects without an ObjectStream, you run the risk that the objects will be incorrectly rehydrated.
See the topics on implementing persistence for more details on implementing persistence on your custom objects with IObjectStream.
| Interfaces | Description |
|---|---|
| IDocumentVersion | Provides access to members that control the document version. |
| IObjectStream | Provides access to members used to make objects and object references persistant. Use of this interface allows multiple references to the same object to be stored properly. |
| IStream |
One limitation when developing with VB6 is that you cannot call IObjectStream::LoadObject due to its method signature. This does not normally cause a problem when implementing persistence for objects with IPersistVariant since the object stream is created and used automatically by the ArcGIS framework. However, it can be an issue when persisting objects in an ad-hoc manner from VB6. The following code shows a workaround using the IPersistStream interface on a property set holding the object to be persisted (which must also have a persistence implementation), in this case a feature class name. You could persist more than one object by adding more properties to the property set.
Dim pMemoryBlobStream As IMemoryBlobStream
Set pMemoryBlobStream = New MemoryBlobStream
Dim pObjectStream As IObjectStream
Set pObjectStream = New ObjectStream
Set pObjectStream.Stream = pMemoryBlobStream
‘ Following line would work, but you could not rehydrate
‘ the object from VB6, since cant call LoadObject
‘ pObjectStream.SaveObject pDatasetName
‘ Workaround is as follows
Dim pPersistStream As IPersistStream
Dim pPropertySet As IPropertySet
Set pPropertySet = New PropertySet
pPropertySet.SetProperty “FeatureClassName”, pFeatureClassName
Set pPersistStream = pPropertySet
pPersistStream.Save pObjectStream, False
pMemoryBlobStream.SaveToFile “C:\Temp\MyFile.blb”
The following code works around the problem with IObjectStream::LoadObject in VB6; it rehydrates the feature class name object from the file.
Dim pObjectStream As IObjectStream
Set pObjectStream = New ObjectStream
Dim pMemoryBlobStream As IMemoryBlobStream
Set pMemoryBlobStream = New MemoryBlobStream
pMemoryBlobStream.LoadFromFile “C:\Temp\MyFile.blb”
Dim pFeatureClassName As IFeatureClassName
Dim pPropertySet As IPropertySet
Set pPropertySet = New PropertySet
Dim pPersistStream As IPersistStream
Set pPersistStream = pPropertySet
Set pObjectStream.Stream = pMemoryBlobStream
pPersistStream.Load pObjectStream
Set pFeatureClassName = pPropertySet.GetProperty(“FeatureClassName”)