WpRestoreState: Difference between revisions
Appearance
mNo edit summary |
|||
| Line 3: | Line 3: | ||
==Syntax== | ==Syntax== | ||
_wpRestoreState(somSelf, ulReserved) | |||
_wpRestoreState(somSelf, ulReserved) | |||
==Parameters== | ==Parameters== | ||
;''somSelf'' ( | ;''somSelf'' (WPObject *) - input:Pointer to the object on which the method is being invoked. | ||
:Pointer to the object on which the method is being invoked. | |||
:Points to an object of class [[WPObject]]. | :Points to an object of class [[WPObject]]. | ||
;''ulReserved'' ([[ULONG]]) - input:Reserved value; must be 0. | |||
;''ulReserved'' ([[ULONG]]) - input | |||
:Reserved value; must be 0. | |||
==Returns== | ==Returns== | ||
;''rc'' ([[BOOL]]) - returns | ;''rc'' ([[BOOL]]) - returns:Success indicator. | ||
:Success indicator. | |||
::TRUE: Successful completion. | ::TRUE: Successful completion. | ||
::FALSE: Error occurred. | ::FALSE: Error occurred. | ||
==Usage== | ==Usage== | ||
| Line 32: | Line 22: | ||
==Example Code== | ==Example Code== | ||
In this example, wpRestoreState is overridden to restore data from the OS2.INI file. | In this example, wpRestoreState is overridden to restore data from the OS2.INI file. | ||
<PRE> | <PRE> | ||
SOM_Scope void SOMLINK UserSetTitle(nbk *somSelf, | SOM_Scope void SOMLINK UserSetTitle(nbk *somSelf, PSZ pszNewTitle) | ||
PSZ pszNewTitle) | |||
{ | { | ||
nbkData *somThis = nbkGetData(somSelf); | nbkData *somThis = nbkGetData(somSelf); | ||
nbkMethodDebug("nbk","UserSetTitle" | nbkMethodDebug("nbk","UserSetTitle"); | ||
strcpy ( _title, pszNewTitle ); | |||
} | } | ||
/* | /* | ||
Override of wpRestoreState method to restore our data | Override of wpRestoreState method to restore our data | ||
from the OS2.INI file. | from the OS2.INI file. | ||
*/ | |||
SOM_Scope BOOL SOMLINK wpRestoreState(nbk | SOM_Scope BOOL SOMLINK wpRestoreState(nbk *somSelf, ULONG ulReserved) | ||
{ | { | ||
BOOL fSuccess; | BOOL fSuccess; | ||
| Line 74: | Line 45: | ||
nbkMethodDebug("nbk","wpRestoreState"); | nbkMethodDebug("nbk","wpRestoreState"); | ||
ulCount = 40; | ulCount = 40; /* Length of data buffer */ | ||
fSuccess = _wpRestoreData ( somSelf / Our pointer / | fSuccess = _wpRestoreData ( somSelf /* Our pointer */ | ||
, (PSZ) "nbk" / Name of class / | , (PSZ) "nbk" /* Name of class */ | ||
, WPNBK_KEY / Key of data requested / | , WPNBK_KEY /* Key of data requested */ | ||
, (PBYTE) &buf / Where to put data / | , (PBYTE) &buf /* Where to put data */ | ||
, &ulCount ); / Length of data returned */ | , &ulCount ); /* Length of data returned */ | ||
if ( !fSuccess ) | if ( !fSuccess ) | ||
| Line 90: | Line 61: | ||
/* Save initial string to OS2.INI file */ | /* Save initial string to OS2.INI file */ | ||
_wpSaveData ( somSelf /* Pointer to ourself */ | _wpSaveData ( somSelf /* Pointer to ourself */ | ||
, (PSZ) | , (PSZ) "nbk"; /* Class name */ | ||
, WPNBK_KEY /* Key of data */ | , WPNBK_KEY /* Key of data */ | ||
, (PBYTE) buf /* Pointer to data */ | , (PBYTE) buf /* Pointer to data */ | ||
| Line 101: | Line 72: | ||
return (parent_wpRestoreState(somSelf,ulReserved)); | return (parent_wpRestoreState(somSelf,ulReserved)); | ||
} | } | ||
</PRE> | |||
==Related Methods== | ==Related Methods== | ||
Revision as of 22:48, 16 November 2025
This method restores the state of the object which was saved during the processing of the wpSaveState method.
Syntax
_wpRestoreState(somSelf, ulReserved)
Parameters
- somSelf (WPObject *) - input
- Pointer to the object on which the method is being invoked.
- Points to an object of class WPObject.
- ulReserved (ULONG) - input
- Reserved value; must be 0.
Returns
- rc (BOOL) - returns
- Success indicator.
- TRUE: Successful completion.
- FALSE: Error occurred.
Usage
This method is generally called only by the system while it is processing the wpInitData method.
How to Override
This method should be overridden by all classes that provide settings that can be saved. An override of the wpSaveState method is a prerequisite if persistent instance data is desired. Override processing of this method typically includes a series of calls to any combination of the restore state methods: wpRestoreData, wpRestoreLong, wpRestoreString.
Example Code
In this example, wpRestoreState is overridden to restore data from the OS2.INI file.
SOM_Scope void SOMLINK UserSetTitle(nbk *somSelf, PSZ pszNewTitle)
{
nbkData *somThis = nbkGetData(somSelf);
nbkMethodDebug("nbk","UserSetTitle");
strcpy ( _title, pszNewTitle );
}
/*
Override of wpRestoreState method to restore our data
from the OS2.INI file.
*/
SOM_Scope BOOL SOMLINK wpRestoreState(nbk *somSelf, ULONG ulReserved)
{
BOOL fSuccess;
ULONG ulCount;
CHAR buf[40];
nbkData *somThis = nbkGetData(somSelf);
nbkMethodDebug("nbk","wpRestoreState");
ulCount = 40; /* Length of data buffer */
fSuccess = _wpRestoreData ( somSelf /* Our pointer */
, (PSZ) "nbk" /* Name of class */
, WPNBK_KEY /* Key of data requested */
, (PBYTE) &buf /* Where to put data */
, &ulCount ); /* Length of data returned */
if ( !fSuccess )
{
/* first time the object is being restored */
/* initialize string to NULL */
strcpy ( buf, "" );
/* Save initial string to OS2.INI file */
_wpSaveData ( somSelf /* Pointer to ourself */
, (PSZ) "nbk"; /* Class name */
, WPNBK_KEY /* Key of data */
, (PBYTE) buf /* Pointer to data */
, 40 ); /* Length of data to write */
} /* endif */
_UserSetTitle ( somSelf, buf );
return (parent_wpRestoreState(somSelf,ulReserved));
}