Syntax 5: For opening an OLE object in a file into an
OLEStorage
Description
Opens an OLE object in an OLE storage file and loads it into a
storage object in memory.
Applies to
OLE storage objects
Syntax
|
1 |
olestorage.Open ( OLEsourcefile {, readmode {, sharemode } } ) |
|
Argument |
Description |
|---|---|
|
olestorage |
The name of an object variable of type OLEStorage into |
|
OLEsourcefile |
A string specifying the name of an OLE storage file |
|
readmode (optional) |
A value of the enumerated datatype stgReadMode that
|
|
sharemode (optional) |
A value of the enumerated datatype stgShareMode that
|
Return value
Integer.
Returns 0 if it succeeds and one of the following negative values
if an error occurs:
-1 — The file is not an OLE storage file
-3 — The file is not found
-9 — Other error
If any argument’s value is null, Open returns null.
Usage
An OLE storage file is structured like a directory. Each OLE
object can contain other OLE objects (substorages) and other data
(streams). You can open the members of an OLE storage belonging to a
server application if you know the structure of the storage. However,
the PowerBuilder functions for manipulating storages are provided so
that you can build your own storage files for organizing the OLE objects
used in your applications.
The whole file can be an OLE object and substorages within the
file can also be OLE objects. More frequently, the structure for a
storage file you create is a root level that is not an OLE object but
contains independent OLE objects as substorages. Any level in the
storage hierarchy can contain OLE objects or be simply a repository for
another level of substorages.
Opening nested objects
Because you can specify path information within an OLE storage
with a backslash as the separator, you can open a deeply nested object
with a single call to Open. However, there is no error checking for
the path you specify and if the Open fails, you wo not know why. It is
strongly recommended that you open each object in the path until you
get to the one you want.
Examples
This example opens the object in the file MYSTUFF.OLE and loads it
into the OLEStorage variable stg_stuff:
|
1 2 3 4 5 |
integer result OLEStorage stg_stuff stg_stuff = CREATE OLEStorage result = stg_stuff.Open("c:ole2mystuff.ole") |
This example opens the same object for reading:
|
1 2 3 4 5 6 |
integer result OLEStorage stg_stuff stg_stuff = CREATE OLEStorage result = stg_stuff.Open("c:ole2mystuff.ole", & stgRead!) |
This example opens the object in the file MYSTUFF.OLE and loads it
into the OLEStorage variable stg_stuff, as in the previous example. Then
it opens the substorage drawing_1 into a second storage variable, using
Syntax 6 of Open. This example does not include code to close and
destroy any of the objects that were opened.
|
1 2 3 4 5 6 7 8 9 10 |
integer result OLEStorage stg_stuff, stg_drawing stg_stuff = CREATE OLEStorage result = stg_stuff.Open("c:ole2mystuff.ole") IF result >= 0 THEN stg_drawing = CREATE OLEStorage result = opest_drawing.Open("drawing_1", & stgRead!, stgDenyNone!, stg_stuff) END IF |
This example opens the object in the file MYSTUFF.OLE and loads it
into the OLEStorage variable stg_stuff. Then it checks whether a stream
called info exists in the OLE object, and if so, opens it with read
access using Syntax 7 of Open. This example does not include code to
close and destroy any of the objects that were opened.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
integer result boolean str_found OLEStorage stg_stuff OLEStream mystream stg_stuff = CREATE OLEStorage result = stg_stuff.Open("c:ole2mystuff.ole") IF result < 0 THEN RETURN result = stg_stuff.MemberExists("info", str_found) IF result < 0 THEN RETURN IF str_found THEN mystream = CREATE OLEStream result = mystream.Open(stg_stuff, "info", & stgRead!, stgDenyNone!) IF result < 0 THEN RETURN END IF |
See also