Jump to content

wpRestoreState

From EDM2
Revision as of 00:18, 2 September 2025 by Martini (talk | contribs) (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) -...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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) - returns
Success indicator .
    • TRUE: Successful completion** .
    • FALSE: Error occurred** .

Remarks

This method restores the object's state that was saved during the processing of the `wpSaveState` method . When an object needs extra initialization that requires invoking other methods, this should be done from `wpRestoreState`. The `wpRestoreData`, `wpRestoreLong`, and `wpRestoreString` methods can only be called during the processing of `wpRestoreState` . Conversely, `wpSaveDeferred` cannot be called from within `wpRestoreState` .

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** . Overriding the `wpSaveState` method is a **prerequisite** if persistent instance data is desired .

Override processing of `wpRestoreState` typically includes a series of calls to any combination of the following restore state methods :

  • `wpRestoreData`
  • `wpRestoreLong`
  • `wpRestoreString`

Example Code

Declaration: ```

  1. define INCL_WINWORKPLACE
  2. 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); ``` The following example demonstrates an override of `wpRestoreState` to restore data from the `OS2.INI` file. If restoration fails, it initializes a string to NULL and saves it .

```c 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; 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)); } ```

Related Methods