IModelKeyReference2::OverrideContextObject 方法 (dbgmodel.h)
OverrideContextObject 方法(僅存在於 IModelKeyReference2上),是一種進階方法,用來永久改變這個索引鍵參考將傳遞給任何基礎屬性存取子的 GetValue 或 SetValue 方法的內容物件。 傳遞至這個方法的物件也會從 GetContextObject 的呼叫傳回。 腳本提供者可以使用此方法來復寫特定動態語言行為。 大部分的客戶端不應該呼叫此方法。
語法
HRESULT OverrideContextObject(
IModelObject *newContextObject
);
參數
newContextObject
要傳遞至任何基礎屬性存取子的 GetValue 或 SetValue 方法的新內容物件。
傳回值
此方法會傳回表示成功或失敗的 HRESULT。
言論
程式代碼範例
ComPtr<IModelObject> spObject; /* get an object */
ComPtr<IModelObject> spAdjustedContext; /* get the object you'd like to adjust context to */
ComPtr<IModelKeyReference> spKeyRef;
if (SUCCEEDED(spObject->GetKeyReference(L"Id", &spKeyRef, nullptr)))
{
// At this moment, spKeyRef->GetContextObject() and
// spKeyRef->GetOriginalObject() will return the same value
ComPtr<IModelKeyReference2> spKeyRef2;
if (SUCCEEDED(spKeyRef.As(&spKeyRef2)))
{
if (SUCCEEDED(spKeyRef2->OverrideContextObject(spAdjustedContext.Get())))
{
// Now, spKeyRef->GetContextObject() will return spAdjustedContext
// and spKeyRef->GetOriginalObject() will return spObject
// Very few clients will want to do this. It is useful for some
// bridges between dynamic languages and the data model.
}
}
}
要求
要求 | 價值 |
---|---|
標頭 | dbgmodel.h |