Syntax 2: For OLE objects
Description
Saves an OLE object in an OLE control or an OLE storage
object.
Syntax
|
1 |
oleobject.Save ( ) |
|
Argument |
Description |
|---|---|
|
oleobject |
The name of an OLE control or an OLE storage |
Return value
Integer. Returns 0 if it succeeds and one of the following
negative values if an error occurs:
-1 — Control is empty
-9 — Other error
If oleobject is null, Save returns null.
Usage
When you save an OLE object, PowerBuilder saves it according to
the current connection between it and an open storage or file. You
establish an initial connection when you call the Open function. When
you call SaveAs, the old connection is ended and a new connection is
established with another storage or file.
When you call Save for an OLE control, PowerBuilder saves the
object in the OLE control to the storage to which it is currently
connected. The storage can be a storage object variable or a OLE storage
file.
If the data has never been saved in the server application, so
that there is no file on disk, the Save function in PowerBuilder returns
an error.
When you call Save for a storage object variable, PowerBuilder
saves the storage to the file, or substorage within the file, to which
it is currently connected. You must have previously established a
connection to an OLE storage file on disk, or a substorage within the
file, either with Open or SaveAs.
When do you have to save twice?
If you create a storage object variable and then open that
object in an OLE control, you need to call Save twice to write changed
OLE information to disk: once to save from the object in the control
to the storage, and again to save the storage to its associated
file.
Examples
This example saves the object in the control ole_1 back to the
storage from which it was loaded, either a storage object variable or a
file on disk:
|
1 2 |
integer result result = ole_1.Save() |
This example saves a storage object to its file. Olestor_1 is an
instance variable of type olestorage:
|
1 2 |
integer result result = olestor_1.Save() |
In a window’s Open script, this code creates a storage variable
ole_stor, which is declared as an instance variable, and associates it
with a storage file that contains several Visio drawings. The script
then opens one of the drawings into the control ole_draw. After the user
activates and edits the object, the script for a Save button saves the
object to the storage and then to the storage’s file.
The script for the window’s Open event includes:
|
1 2 3 4 |
OLEStorage stg_stor stg_stor = CREATE OLEStorage stg_stor.Open("myvisio.ole") ole_draw.Open(ole_stor, "visio_drawing1") |
The script for the Save button’s Clicked event is:
|
1 2 3 |
integer result result = ole_draw.Save() IF result = 0 THEN ole_stor.Save() |
See also