Share via


Metodo IModelKeyReference::SetKey (dbgmodel.h)

Il metodo SetKey in un riferimento chiave si comporta come il metodo SetKey in IModelObject . Assegnerà il valore della chiave. Se la chiave originale è una funzione di accesso alla proprietà, la funzione di accesso alla proprietà verrà sostituita. Non chiamerà il metodo SetValue sulla funzione di accesso della proprietà.

Sintassi

HRESULT SetKey(
  IModelObject *object,
  IKeyStore    *metadata
);

Parametri

object

Valore da assegnare alla chiave.

metadata

Metadati facoltativi da associare alla chiave.

Valore restituito

Questo metodo restituisce HRESULT che indica l'esito positivo o negativo.

Commenti

Codice di esempio

ComPtr<IDataModelManager> spManager; /* get the data model manager */
ComPtr<IModelObject> spObject;       /* get an object */

ComPtr<IModelKeyReference> spKeyRef;
if (SUCCEEDED(spObject->GetKeyReference(L"Id", &spKeyRef, nullptr)))
{
    VARIANT vtValue;
    vtValue.vt = VT_UI8;
    vtValue.ullVal = 42;

    ComPtr<IModelObject> sp42;
    if (SUCCEEDED(spManager->CreateIntrinsicObject(ObjectIntrinsic, &vtValue, &sp42)))
    {
        if (SUCCEEDED(spKeyRef->SetKey(sp42.Get(), nullptr)))
        {
            // The "Id" key has been overwritten with the value 42.  
            // If the "Id" key originally was a property accessor, it isn't anymore.
            // This would not have called SetValue() on the property accessor.  
            // It replaced the property accessor with a static "42".
        }
    }
}

Requisiti

Requisito Valore
Intestazione dbgmodel.h

Vedi anche

Interfaccia IModelKeyReference