background image
C H A P T E R 1 2
Special-Purpose Objects for Data Storage and Retrieval
Using Special-Purpose Data Storage Objects
12-15
Implementing the EntryAccess Method
12
Each of your mock entry handler frames must supply an
EntryAccess
method
that creates a cached frame containing the mock entry's data, installs the cached
frame in the mock entry, and returns the cached frame. This method is called when
the system attempts to access a cached frame that is not present.
The system passes the mock entry to your
EntryAccess
method when it is
invoked. This method calls the
EntrySetCachedObject
function to install the
cached frame in the mock entry and then returns the cached frame.
The following code fragment provides a simple example of an
EntryAccess
method:
myHandler := {
object: {foo: 'bar},
EntryAccess: func (mockEntry)
begin
// install cached frame
EntrySetCachedObject(mockEntry, object);
// return cached frame
object;
end,
// your additional slots and methods here
...}
Creating a New Mock Entry
12
The
NewMockEntry
global function creates a new mock entry object having a
specified handler and cached frame. Your application can use this method to create
a new mock entry; for example, in response to a mockSoup
:Add()
message.
The handler frame you pass to the
NewMockEntry
function must define an
EntryAccess
method, as described in "Implementing the EntryAccess Method"
on page 12-15. The handler may also contain supporting methods or data used by
the mock entry; for example, it might hold information local to a specific mock
entry or information required to retrieve the mock entry's data.
Depending on your needs, you can create new mock entries with or without their
corresponding cached frames. To create a mock entry with its cached frame already
installed, pass both the handler and the cached frame to this function.
To create a mock entry without a cached frame, pass
nil
as the value of the
cachedObject
parameter to the
NewMockEntry
function. When a slot in the
returned mock entry is accessed, the handler's
EntryAccess
method is invoked
to create the cached entry if it is not present.
© 2007-2017, o7 studio » при воспроизведении материала сайта ссылка обязательна