An OleFile works seamlessly with an
OleClient in the storage and retrieval of its contained OLE object's data. An
OleFile can store multiple OLE clients and, hence, it requires that each one be given a unique name when put into the file. OLE files also allow arbitrary application data to be stored with the
OleClient in the file. These attributes of application data are stored in the
OleFile under the same name as the OLE object they are associated with. Finally, an
OleFile permits one global, unnamed set of application data attributes to be stored in the file.
Given a fully qualified path name string, an OleFile can create and open a compound file for storage through its
create: class method. Once opened, an OLE object can be stored using the
saveWidget:named: instance method. For example, all the embedded or linked OLE objects in an application can be saved using:
Once an OleFile is created, all
OleClient widgets in the application are obtained from the
OleMainWindow through its
oleWidgets method. This example assumes that when each
OleClient widget is created, it is given a unique name which it uses as the unique
OleFile storage name.
An OleFile must be closed with its
close method before any OLE object data is committed to the file.
An OleFile can be opened, through its
open: class method, on an existing file as long as the file was originally created as an
OleFile. If it was not, the
open: fails. An OLE object's data is retrieved from an
OleFile into an existing
OleClient widget. The
storageNames instance method of
OleFile can be used to obtain all the storage names from the file so that the
OleClient widgets can be created with the same names they were saved under. Given the storage names, each
OleClient can be restored from the
OleFile using its
restoreWidget:named: instance method. For example, the OLE objects saved in the above example can be restored using:
In this example, the OleClient widgets are created with default size and position. The following section describes saving additional attributes of the widgets in the file.
An arbitrary, named data set can also be stored in an OleFile. This permits, for example, data attributes of an
OleClient to be stored in the file under the same name as the
OleClient. The data set to be saved must be contained in a
ByteArray, which can be filled in a variety of ways, including by using the Swapper tool. The
OleFile instance method
saveAttributes:named: saves a
ByteArray of data to the file. For example, the
saveWidgetTo: method above can be enhanced to save each widget's position and size:
Additional methods of OleFile can be used to save and restore unnamed data sets to a file. The methods, which also work with byte arrays, are
saveAttributes: and
restoreAttributes.
Copyright 2005, 2020 Instantiations, Inc. All rights reserved.