Jaa


IExpressionEval::EvalInContext Method

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

Use this method to evaluate an expression against a pre-established context stored in the context cache.

HRESULT IExpressionEval::EvalInContext(
  long nExprID,
  IExprEvalContext* pContext,
  VARIANT* pvResult
);
Function EvalInContext(
    nExprID As Long,
    pContext As Object
) As Variant

Parameters

  • nExprID
    [C++]

    [in] A long that contains the unique identification of the expression in the expression store.

    [Visual Basic]

    A Long that contains the unique identification of the expression in the expression store.

  • pContext
    [C++]

    [in] A pointer to an IExprEvalContext interface of an ExprEvalContext object that identifies the specific context for this evaluation.

    [Visual Basic]

    An ExprEvalContext object that identifies the specific context for this evaluation.

  • pvResult
    [C++]

    [out, retval] A pointer to a VARIANT indicating the result of the expression evaluated in the specified context.

Return Value

[C++]

This method returns an HRESULT indicating whether it completed successfully. See the Error Values section for more details. The result of evaluating the expression is contained in the pvResult parameter. This result may be TRUE, FALSE, or NULL. NULL indicates the expression could not be evaluated.

[Visual Basic]

This method returns a Variant indicating the results of evaluating the expression in the specified context. This result may be True, False, or Nothing. Nothing indicates the expression could not be evaluated.

Error Values

[C++]

This method returns S_OK (0x00000000) to indicate success and either standard or custom COM HRESULT error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.

[Visual Basic]

This method sets the Number property of the global Err object to S_OK (&H00000000) to indicate success and to either standard or custom COM error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.

The following table shows the custom COM errors, and the standard COM errors with special meanings, that this method can return.

Constant

Value

Description

E_EXPR_BADCONNECTION

0x8110001F

Invalid connection

E_EXPR_BADEXPRID

0x8110000A

Invalid expression ID specified

E_EXPR_NOCONNECTIONSTRING

0x8110000D

No connection string specified

E_EXPR_MISSINGPROP

0x8110001D

Invalid ExprEvalContext object

E_EXPR_NOTFOUND

0x81100012

Could not find the specified expression ID, nExprID, in the expression store

Additional information may be available using the global Err object, which can be accessed using the API function GetErrorInfo. In particular, the GetDescription method of the IErrorInfo interface may return a text description of the error.

Additional information may be available using the global Err object. In particular, the Description property may contain a text description of the error.

Remarks

The Eval method creates and discards an evaluation context for every evaluation. Evaluating against a stored context optimizes performance when multiple expressions need to be evaluated in the same context. Create the context for evaluation using the CreateEvalContext method.

Expression results are also stored in the context cache. If the result of a particular expression is requested multiple times from the same ExprEvalContext object using the EvalInContext method, the result is retrieved from the cache rather than by re-evaluating the expression, further increasing efficiency.

Warning

The state of the profile objects that comprise the context should not be externally changed during the lifetime of the ExprEvalContext object; doing so leads to non-deterministic evaluation results.

The Connect method must be called before using the EvalInContext method.

The pvResult parameter contains valid data only if the method completes successfully.

Example

' oEvalContext is an ExprEvalContext object.
' vResult is a Variant.

vResult = oExpressionEval.Eval(2134, oEvalContext)

See Also

Other Resources

ExpressionEval Object

IExpressionEval::Connect Method

IExpressionEval::CreateEvalContext Method

IExpressionEval::Eval Method

IExpressionEval::LoadExpr Method