WpRestoreState: Difference between revisions
Created page with "{{DISPLAYTITLE:wpRestoreState}} This instance 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) -..." |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:wpRestoreState}} | {{DISPLAYTITLE:wpRestoreState}} | ||
This | This method restores the state of the object which was saved during the processing of the [[wpSaveState]] method. | ||
==Syntax== | ==Syntax== | ||
_wpRestoreState(somSelf, ulReserved) | |||
<PRE> | |||
_wpRestoreState(somSelf, ulReserved); | |||
</PRE> | |||
==Parameters== | ==Parameters== | ||
;''somSelf'' ([[WPObject]] *) - input | ;''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 | ;''ulReserved'' ([[ULONG]]) - input | ||
:Reserved value; | :Reserved value; must be 0. | ||
==Returns== | ==Returns== | ||
;''rc'' ([[BOOL]]) - returns | ;''rc'' ([[BOOL]]) - returns | ||
:Success indicator . | :Success indicator. | ||
:: | ::TRUE: Successful completion. | ||
:: | ::FALSE: Error occurred. | ||
==Remarks== | ==Remarks== | ||
This method restores the object | This method restores the state of the object that was saved during the processing of the [[wpSaveState]] method. | ||
==Usage== | ==Usage== | ||
This method is | This method is generally called only by the system while it is processing the [[wpInitData]] method. | ||
==How to Override== | ==How to Override== | ||
This method | 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]]. | ||
Override processing of | |||
==Example Code== | ==Example Code== | ||
Declaration: | Declaration: | ||
<PRE> | |||
#define INCL_WINWORKPLACE | #define INCL_WINWORKPLACE | ||
#include <os2.h> | #include <os2.h> | ||
WPObject | WPObject somSelf; / Pointer to the object on which the method is being invoked. / | ||
ULONG | ULONG ulReserved; / Reserved value; must be 0. / | ||
BOOL | BOOL rc; / Success indicator. */ | ||
rc = _wpRestoreState(somSelf, ulReserved); | rc = _wpRestoreState(somSelf, ulReserved); | ||
</PRE> | |||
In this example, wpRestoreState is overridden to restore data from the OS2.INI file. | |||
<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 ); | strcpy ( _title, pszNewTitle ); | ||
} | } | ||
/* | /* | ||
Override of wpRestoreState method to restore our data | |||
*/ | |||
SOM_Scope BOOL SOMLINK wpRestoreState(nbk *somSelf, | from the OS2.INI file. | ||
ULONG ulReserved) | */ | ||
{ | SOM_Scope BOOL SOMLINK wpRestoreState(nbk *somSelf, | ||
BOOL fSuccess; | ULONG ulReserved) | ||
ULONG ulCount; | { | ||
CHAR buf; | BOOL fSuccess; | ||
nbkData *somThis = nbkGetData(somSelf); | ULONG ulCount; | ||
nbkMethodDebug("nbk","wpRestoreState"); | CHAR buf[40]; | ||
ulCount = 40; /* Length of data buffer | |||
fSuccess = _wpRestoreData ( somSelf / | nbkData *somThis = nbkGetData(somSelf); | ||
, (PSZ) "nbk" / | nbkMethodDebug("nbk","wpRestoreState"); | ||
, WPNBK_KEY / | |||
, (PBYTE) &buf / | ulCount = 40; /* Length of data buffer / | ||
, &ulCount ); / | fSuccess = _wpRestoreData ( somSelf / Our pointer / | ||
if ( !fSuccess ) | , (PSZ) "nbk" / Name of class / | ||
{ | , WPNBK_KEY / Key of data requested / | ||
/* first time the object is being restored */ | , (PBYTE) &buf / Where to put data / | ||
/* initialize string to NULL */ | , &ulCount ); / Length of data returned */ | ||
strcpy ( buf, | |||
/* Save initial string to OS2.INI file */ | if ( !fSuccess ) | ||
_wpSaveData ( somSelf /* Pointer to ourself */ | { | ||
, (PSZ) | /* first time the object is being restored */ | ||
, WPNBK_KEY /* Key of data */ | |||
, (PBYTE) buf /* Pointer to data */ | /* initialize string to NULL */ | ||
, 40 ); /* Length of data to write */ | strcpy ( buf, "" ); | ||
} /* endif */ | |||
_UserSetTitle ( somSelf, buf ); | /* Save initial string to OS2.INI file */ | ||
return (parent_wpRestoreState(somSelf,ulReserved)); | _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)); | |||
} | |||
</PRE> | |||
==Related Methods== | ==Related Methods== | ||
* | * [[wpRestoreData]] | ||
* | * [[wpRestoreLong]] | ||
* | * [[wpRestoreState]] | ||
* | * [[wpRestoreString]] | ||
* | * [[wpSaveData]] | ||
* | * [[wpSaveDeferred]] | ||
* | * [[wpSaveImmediate]] | ||
* | * [[wpSaveLong]] | ||
* | * [[wpSaveState]] | ||
* [[wpSaveString]] | |||
[[Category:Workplace Instance Methods]] | [[Category:Workplace Instance Methods]] |
Latest revision as of 00:22, 2 September 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.
Remarks
This method restores the state of the object that was saved during the processing of the wpSaveState method.
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
Declaration:
#define INCL_WINWORKPLACE #include <os2.h> WPObject somSelf; / Pointer to the object on which the method is being invoked. / ULONG ulReserved; / Reserved value; must be 0. / BOOL rc; / Success indicator. */ rc = _wpRestoreState(somSelf, ulReserved);
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)); }