Método IKeyStore::GetKey (dbgmodel.h)

El método GetKey es análogo al método GetKey en IModelObject. Devolverá el valor de la clave especificada si existe en el almacén de claves o en el almacén primario del almacén de claves. Tenga en cuenta que si el valor de la clave es un descriptor de acceso de propiedad, no se llamará al método GetValue en el descriptor de acceso de propiedad. Se devolverá el IModelPropertyAccessor real en un IModelObject . Es habitual que un cliente llame a GetKeyValue por este motivo.

Sintaxis

HRESULT GetKey(
  PCWSTR                          key,
  _COM_Errorptr_opt_ IModelObject **object,
  IKeyStore                       **metadata
);

Parámetros

key

Nombre de la clave para la que se va a obtener un valor

object

El valor de la clave se devolverá en este argumento.

metadata

El almacén de metadatos asociado a esta clave se devolverá opcionalmente en este argumento. No hay ningún uso presente para los metadatos de segundo nivel. Por lo tanto, este argumento se debe especificar normalmente como null.

Valor devuelto

Este método devuelve HRESULT que indica éxito o error. Los valores devueltos E_BOUNDS (o E_NOT_SET en algunos casos) indican que no se encontró la clave.

Comentarios

Ejemplo de código

ComPtr<IModelObject> spObject; /* get an object */
ComPtr<IKeyStore> spMetadata;  /* get a key store from spObject (say 
                                  returned from GetKeyValue) */

ComPtr<IModelObject> spRadixKey;
if (SUCCEEDED(spMetadata->GetKey(L"PreferredRadix", &spRadixKey, nullptr)))
{
    // Since this is GetKey and not GetKeyValue, spRadixKey *MAY* be a 
    // property accessor.  Check and fetch.
    ModelObjectKind kind;
    if (SUCCEEDED(spRadixKey->GetKind(&kind)))
    {
        if (kind == ObjectPropertyAccessor)
        {
            VARIANT vtProp;
            if (SUCCEEDED(spRadixKey->GetIntrinsicValue(&vtProp)))
            {
                // There is a guarantee in-process that the IUnknown here 
                // is IModelPropertyAccessor because of the ObjectPropertyAccessor.
                IModelPropertyAccessor *pProperty = 
                    static_cast<IModelPropertyAccessor *>(vtProp.punkVal);
                
                ComPtr<IModelObject> spRadix; 

                // It is important that the context object be the object where 
                // the metadata store CAME FROM.  Hence the second argument
                // of spObject.Get().  Note that if you use GetKeyValue on the store,
                // this is automatically handled for you.
                if (SUCCEEDEDED(pProperty->GetValue(L"PreferredRadix", 
                                                    spObject.Get(), 
                                                    &spRadix)))
                {
                    // spRadix has the radix.  Use GetIntrinsicValueAs to unbox.
                }
                VariantClear(&vtProp);
            }
        }
        else
        {
            // spRadixKey has the radix.  Use GetIntrinsicValueAs to unbox.
        }
    }
}

Requisitos

Requisito Valor
Header dbgmodel.h

Consulte también

Interfaz IKeyStore