OPT_VALUE |
OPT_VALUE( value, default )
Retrieve an optional parameter as a mb_value_t. Return the default value if the parameter wasn't present. You can use the predefined constan MB_EMPTY_VALUE to initialize an empty value.
The mb_value_t type is similar to the OLE data type VARIANT. It contains a tag with the type, the name of the variable and the value of the variable.
This example is from the code from PROFILE.Read
Example
///////////////////////////////////////////////////////////////////////////// // result = PROFILE.Read( hHandle AS HANDLE, // key AS STRING, // valuename AS STRING, // default AS VARIANT ) AS VARIANT // int mb_ext_read_profile( mb_interpreter_t* s, void** l ) { AFX_MANAGE_STATE( AfxGetStaticModuleState() ); //////////////////////////////////////////////////////////////////////////
mb_value_t value = MB_EMPTY_VALUE;
BEGIN_PARSE( s, l ) POP_HANDLE( hHandle ) POP_STRING( lpSection ) POP_STRING( lpEntry ) OPT_VALUE( defval, MB_EMPTY_VALUE ) END_PARSE
CXMLProfile* pProfile = (CXMLProfile*)GetHandle( g_arrProfiles, (int)hHandle );
if ( pProfile ) { CString strDefault;
if ( defval.type == MB_DT_INT ) { strDefault.Format( "%d", defval.value.integer ); } else if ( defval.type == MB_DT_REAL ) { strDefault.Format( "%f", defval.value.float_point ); } else if ( defval.type == MB_DT_STRING ) { strDefault.Format( "%s", defval.value.string ); } else { RETURN_ERROR( SE_RN_INVALID_ARGUMENT ); } endif
CString str = pProfile->GetProfileString( lpSection, lpEntry, strDefault ); String2Value( str, value ); } else { RETURN_ERROR( SE_RN_BAD_HANDLE ); } endif
mb_check( mb_push_value( s, l, value ) );
return MB_FUNC_OK; } endfunc |