Purpose
This property is used to import or export the entire database as
a byte array.
Syntax (Read/Write Property)
(Let)
object.BLOB()
= ByteArray
(Get)
ByteArray
= object.BLOB()
| ByteArray
(Byte Array) |
|
The
byte array to assign to the property. This will typically be a byte
array that has been exported from another database. It contains
its byte-size, followed by the count of the number of records in
the database, followed by a table containing the actual keys and
data. |
| ByteArray
(Byte Array) |
|
The
byte array returned by the property. This byte array can be assigned
to another Compact Data Pak, transported over a network, saved to
disk, or handled in any way you wish. You can even save it as a
single record in another Data Pak (see the example below). |
Notes
(Let)
Use this property to load the entire database in a single function
call. You will normally use this property to copy a database from one
object to another. Because this is the default property, it does not
normally need to be qualified. For example, this will work:
'Create
2 databases
Dim CDP1 As
rtCDP.rtCompactDataPak
Set CDP1 = New rtCDP.rtCompactDataPak
Dim
CDP2 As rtCDP.rtCompactDataPak
Set CDP2 = New rtCDP.rtCompactDataPak
'Now
add a record to the first database
CDP1.Append "Name", "John Doe"
'Now copy the database from one object to another.
'It is not necessary to say CDP2.BLOB
= CDP1.BLOB
'because BLOB is the default property (but you could).
CDP2 = CDP1
'Print
the value of the first record in the second database
Debug.Print CDP2.Data("Name")
'"John Doe" gets printed to the Immediate Pane
Notes
(Get)
This returns the entire database as a byte array. This is useful if
you want to save state information about your application to disk, or
transmit it over a network (or the Internet).
This
sample loads some application state information in the database and
then saves it in a file in the application's root directory.
'Create
the database
Dim CDP As
rtCDP.rtCompactDataPak
Set CDP = New rtCDP.rtCompactDataPak
'Now
add some state information to the database
CDP.Data("WindowState") = "Maximized"
CDP.Data("OpenDocument")
= "Letter to Staff.doc"
'Save
the entire database to a byte array
Dim DataBuffer()
as Byte
DataBuffer = CDP.BLOB
'Now
save the entire database to disk
Dim FileNumber as
Long: FileNumber
= FreeFile
Open App.Path &
"\State" For Binary Access Write
As #FileNumber
Put #FileNumber,
, DataBuffer
Close #FileNumber
This
sample reloads the application state information from the file created
in the previous sample into a database.
'Create
the database
Dim CDP As
rtCDP.rtCompactDataPak
Set CDP = New rtCDP.rtCompactDataPak
'Get the filespec, free file number, resize the
data buffer
Dim
FileName As
String: FileName
= App.Path & "\State"
Dim FileNumber As
Long: FileNumber
= FreeFile
Dim DataBuffer() As
Byte: ReDim DataBuffer(FileLen(FileName))
'Open the file, load the data buffer, close the
file
Open FileName For
Binary Access Read As #FileNumber
Get #FileNumber, , DataBuffer
Close #FileNumber
'Now, transfer the data back into the database
CDP.BLOB = DataBuffer
'Now
the database is exactly the same as when it was saved
Dim WindowState As
String, OpenDocument As String
WindowState = CDP.Data("WindowState")
OpenDocument
= CDP.Data("OpenDocument")
Error
Values (Let)
After calling this property, the property ErrorNumber
will report one of the following values:
rtCDP_ErrNoError
rtCDP_ErrPackageCorrupt
Error
Values (Get)
This property does not change the state of the ErrorNumber
property.
Example
Objective: Save a database inside a single record of another database.
You can create a sort of database heirarchy using this method.
'Create
2 databases
Dim CDP As
rtCDP.rtCompactDataPak
Set CDP = New rtCDP.rtCompactDataPak
Dim
CDP2 As rtCDP.rtCompactDataPak
Set CDP2 = New rtCDP.rtCompactDataPak
'Add
some records to the second database
CDP2.Append "Port Richey, Florida",
"34668"
CDP2.Append "New Port Richey, Florida", "34653"
CDP2.Append
"Jamestown, New York", "14701"
'Now save the entire second database inside a
'single record of the first database
CDP.AppendB "Zip Code List", CDP2.BLOB
'Now create a third database and retrieve the
saved
'second database from a record in the first one
Dim
CDP3 As rtCDP.rtCompactDataPak
Set CDP3 = New rtCDP.rtCompactDataPak
'NOTE: Must use DataB because the record has binary
data
CDP3.BLOB = CDP.DataB("Zip Code List")
'Now you can use the third database just like
the second...
'Print "34653" to the Immediate Pane
Debug.Print CDP3.Data("New Port Richey,
Florida")
Version
History
(Let) 1.0 2/28/2001 Tested
(Get) 1.0 2/28/2001 Tested
See
Also
BLOBSize