Jump to content

WpRestoreData: Difference between revisions

From EDM2
Created page with "{{DISPLAYTITLE:wpRestoreData}} This instance method is called to allow the object to **restore its binary instance data**. ==Syntax== _wpRestoreData(somSelf, pszClass, ulKey, pValue, pcbValue) ==Parameters== ;''somSelf'' (WPObject *) - input :Pointer to the object on which the method is being invoked. :Points to an object of class WPObject. ;''pszClass'' (PSZ) - input :Pointer to the class name. It is a pointer to a zero-terminated string that contains an..."
 
No edit summary
 
Line 1: Line 1:
{{DISPLAYTITLE:wpRestoreData}}
{{DISPLAYTITLE:wpRestoreData}}
This instance method is called to allow the object to **restore its binary instance data**.
This instance method is called to allow the object to restore its binary instance data.


==Syntax==
==Syntax==
Line 11: Line 11:


;''pszClass'' ([[PSZ]]) - input
;''pszClass'' ([[PSZ]]) - input
:Pointer to the class name. It is a pointer to a zero-terminated string that contains any unique string, with the class name recommended but not enforced.
:Pointer to the class name.
:A pointer to a zero-terminated string that contains any unique string. The class name is recommended but not enforced.


;''ulKey'' ([[ULONG]]) - input
;''ulKey'' ([[ULONG]]) - input
:Class-defined identifier.
:A class-defined identifier that correlates to a particular instance data variable.
:A class-defined identifier that correlates to a particular instance data variable.


Line 20: Line 22:


;''pcbValue'' ([[PULONG]]) - in/out
;''pcbValue'' ([[PULONG]]) - in/out
:Size of the data block to be restored. If `pValue` is NULL, the actual size is returned in `pcbValue`.
:Size of the data block to be restored.
:If ''pValue'' is NULL, the actual size is returned in ''pcbValue''.


==Returns==
==Returns==
;''rc'' ([[BOOL]]) - returns
;''rc'' ([[BOOL]]) - returns
:Success indicator.
:Success indicator.
::**TRUE: Successful completion**.
::TRUE: Successful completion.
::**FALSE: Error occurred**.
::FALSE: Error occurred.


==Remarks==
==Remarks==
This method restores data that was saved by a call to the `wpSaveData` method.
This method restores data that was saved by a call to [[wpSaveData]].


==Usage==
==Usage==
This method can be called **only during the processing of the `wpRestoreState` method**.
This method can be called only during the processing of the [[wpRestoreState]] method.


==How to Override==
==How to Override==
This method is **generally not overridden**.
This method is generally not overridden.


==Example Code==
==Example Code==
Line 43: Line 46:
#include <os2.h>
#include <os2.h>


WPObject     *somSelf;     /* Pointer to the object on which the method is being invoked. */
WPObject     *somSelf;   /* Pointer to the object on which the method is being invoked. */
PSZ         pszClass;   /* Pointer to the class name. */
PSZ           pszClass; /* Pointer to the class name. */
ULONG       ulKey;     /* Class-defined identifier. */
ULONG         ulKey;     /* Class-defined identifier. */
PBYTE       pValue;     /* Address of the data to be restored. */
PBYTE         pValue;   /* Address of the data to be restored. */
PULONG       pcbValue;   /* Size of the data block to be restored. */
PULONG       pcbValue; /* Size of the data block to be restored. */
BOOL         rc;         /* Success indicator. */
BOOL         rc;       /* Success indicator. */


rc = _wpRestoreData(somSelf, pszClass, ulKey, pValue, pcbValue);
rc = _wpRestoreData(somSelf, pszClass, ulKey, pValue, pcbValue);
</PRE>
</PRE>
 
In this example, wpRestoreState is overridden to restore data from the OS2.INI file.
The following example demonstrates an override of `wpRestoreState` to restore data from the `OS2.INI` file, which includes a call to `_wpRestoreData`. If restoration fails, it initializes a string to NULL and saves it using `_wpSaveData`:
<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 );
 
    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 *somSelf,
SOM_Scope BOOL   SOMLINK wpRestoreState(nbk   *somSelf,
ULONG ulReserved)
                                            ULONG ulReserved)
{
{
BOOL fSuccess;
    BOOL fSuccess;
ULONG ulCount;
    ULONG ulCount;
CHAR buf;
    CHAR buf[40];
nbkData *somThis = nbkGetData(somSelf);
 
nbkMethodDebug("nbk","wpRestoreState");
    nbkData *somThis = nbkGetData(somSelf);
ulCount = 40; /* Length of data buffer */
    nbkMethodDebug("nbk","wpRestoreState");
fSuccess = _wpRestoreData ( somSelf /* Our pointer */
 
, (PSZ) "nbk" /* Name of class */
    ulCount = 40;                                     /* Length of data buffer */
, WPNBK_KEY /* Key of data requested */
    fSuccess = _wpRestoreData ( somSelf                 /* Our pointer */
, (PBYTE) &buf /* Where to put data */
                              , (PSZ) "nbk"               /* Name of class */
, &ulCount ); /* Length of data returned */
                              , WPNBK_KEY                 /* Key of data requested */
if ( !fSuccess )
                              , (PBYTE) &buf             /* Where to put data */
{
                              , &ulCount   );             /* Length of data returned */
/* first time the object is being restored */
 
/* initialize string to NULL */
    if ( !fSuccess )
strcpy ( buf, "" );
    {
/* Save initial string to OS2.INI file */
        /* first time the object is being restored */
_wpSaveData ( somSelf /* Pointer to ourself */
 
, (PSZ) "nbk" /* Class name */
        /* initialize string to NULL */
, WPNBK_KEY /* Key of data */
        strcpy ( buf, "" );
, (PBYTE) buf /* Pointer to data */
 
, 40 ); /* Length of data to write */
        /* Save initial string to OS2.INI file */
} /* endif */
        _wpSaveData ( somSelf                     /* Pointer to ourself */
_UserSetTitle ( somSelf, buf );
                    , (PSZ) "nbk"                   /* Class name */
return (parent_wpRestoreState(somSelf,ulReserved));
                    , 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>
</PRE>


==Related Methods==
==Related Methods==
*   [[wpRestoreData]]
* [[wpRestoreData]]
*   [[wpRestoreLong]]
* [[wpRestoreLong]]
*   [[wpRestoreState]]
* [[wpRestoreState]]
*   [[wpRestoreString]]
* [[wpRestoreString]]
*   [[wpSaveData]]
* [[wpSaveData]]
*   [[wpSaveDeferred]]
* [[wpSaveDeferred]]
*   [[wpSaveImmediate]]
* [[wpSaveImmediate]]
*   [[wpSaveLong]]
* [[wpSaveLong]]
*   [[wpSaveState]]
* [[wpSaveState]]
*   [[wpSaveString]]
* [[wpSaveString]]


[[Category:Workplace Instance Methods]]
[[Category:Workplace Instance Methods]]

Latest revision as of 00:27, 2 September 2025

This instance method is called to allow the object to restore its binary instance data.

Syntax

_wpRestoreData(somSelf, pszClass, ulKey, pValue, pcbValue)

Parameters

somSelf (WPObject *) - input
Pointer to the object on which the method is being invoked.
Points to an object of class WPObject.
pszClass (PSZ) - input
Pointer to the class name.
A pointer to a zero-terminated string that contains any unique string. The class name is recommended but not enforced.
ulKey (ULONG) - input
Class-defined identifier.
A class-defined identifier that correlates to a particular instance data variable.
pValue (PBYTE) - in/out
Address of the data to be restored.
pcbValue (PULONG) - in/out
Size of the data block to be restored.
If pValue is NULL, the actual size is returned in pcbValue.

Returns

rc (BOOL) - returns
Success indicator.
TRUE: Successful completion.
FALSE: Error occurred.

Remarks

This method restores data that was saved by a call to wpSaveData.

Usage

This method can be called only during the processing of the wpRestoreState method.

How to Override

This method is generally not overridden.

Example Code

Declaration:

#define INCL_WINWORKPLACE
#include <os2.h>

WPObject      *somSelf;    /* Pointer to the object on which the method is being invoked. */
PSZ           pszClass;  /* Pointer to the class name. */
ULONG         ulKey;     /* Class-defined identifier. */
PBYTE         pValue;    /* Address of the data to be restored. */
PULONG        pcbValue;  /* Size of the data block to be restored. */
BOOL          rc;        /* Success indicator. */

rc = _wpRestoreData(somSelf, pszClass, ulKey, pValue, pcbValue);

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

Related Methods