Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
El método GetKey de una referencia de clave se comporta como el método GetKey en IModelObject. Devuelve el valor de la clave subyacente y los metadatos asociados a la clave. Si el valor de la clave es un descriptor de acceso de propiedad, devolverá el descriptor de acceso de propiedad (IModelPropertyAccessor) boxed en un IModelObject. Este método no llamará a los métodos GetValue o SetValue subyacentes en el descriptor de acceso de la propiedad.
Sintaxis
HRESULT GetKey(
_COM_Errorptr_opt_ IModelObject **object,
IKeyStore **metadata
);
Parámetros
object
El valor de la clave se devolverá aquí.
metadata
Aquí se devolverán metadatos opcionales asociados a la clave.
Valor devuelto
Este método devuelve HRESULT que indica éxito o error.
Observaciones
de ejemplo de código de
ComPtr<IModelObject> spObject; /* get an object */
ComPtr<IModelKeyReference> spKeyRef;
if (SUCCEEDED(spObject->GetKeyReference(L"Id", &spKeyRef, nullptr)))
{
ComPtr<IModelObject> spKey;
if (SUCCEEDED(spKeyRef->GetKey(&spKey, nullptr)))
{
// spKey contains the equivalent of spObject->GetKey(L"Id", &spKey, nullptr)
// This may be a property accessor since this was not a GetKeyValue.
// Check and fetch. Note that GetKeyValue would do this for you.
ModelObjectKind kind;
if (SUCCEEDED(spKey->GetKind(&kind)))
{
if (kind == ObjectPropertyAccessor)
{
VARIANT vtProp;
if (SUCCEEDED(spKey->GetIntrinsicValue(&vtProp)))
{
// We are guaranteed *in-process* that the IUnknown is
// an IModelPropertyAccessor via the ObjectPropertyAccessor
IModelPropertyAccessor *pProperty =
static_cast<IModelPropertyAccessor *>(vtProp.punkVal);
// In order to fetch, we need to know the context object and
// the key name. Fetch it from the key reference.
ComPtr<IModelObject> spContextObject;
if (SUCCEEDED(spKeyRef->GetContextObject(&spContextObject)))
{
BSTR keyName;
if (SUCCEEDED(spKeyRef->GetName(&keyName)))
{
ComPtr<IModelObject> spKeyValue;
if (SUCCEEDED(pProperty->GetValue(keyName,
spContextObject.Get(),
&spKeyValue)))
{
// spKeyValue contains the value of the "Id" key.
}
SysFreeString(keyName);
}
}
VariantFree(&vtProp);
}
}
else
{
// spKey contains the value of the "Id" key.
}
}
}
}
Requisitos
| Requisito | Valor |
|---|---|
| encabezado de | dbgmodel.h |