IKeyStore::Metode GetKey (dbgmodel.h)

Metode GetKey dianalogikan dengan metode GetKey pada IModelObject. Ini akan mengembalikan nilai kunci yang ditentukan jika ada di penyimpanan kunci atau penyimpanan induk penyimpanan kunci. Perhatikan bahwa jika nilai kunci adalah pengaktor properti, metode GetValue tidak akan dipanggil pada pengaktor properti. Kotak IModelPropertyAccessor aktual yang dikotak ke dalam IModelObject akan dikembalikan. Biasanya klien akan memanggil GetKeyValue karena alasan ini.

Sintaks

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

Parameter

key

Nama kunci untuk mendapatkan nilai untuk

object

Nilai kunci akan dikembalikan dalam argumen ini.

metadata

Penyimpanan metadata yang terkait dengan kunci ini akan dikembalikan secara opsional dalam argumen ini. Tidak ada penggunaan untuk metadata tingkat kedua. Oleh karena itu, argumen ini biasanya harus ditentukan sebagai null.

Mengembalikan nilai

Metode ini mengembalikan HRESULT yang menunjukkan keberhasilan atau kegagalan. Nilai yang dikembalikan E_BOUNDS (atau E_NOT_SET dalam beberapa kasus) menunjukkan kunci tidak dapat ditemukan.

Keterangan

Sampel Kode

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.
        }
    }
}

Persyaratan

Persyaratan Nilai
Header dbgmodel.h

Lihat juga

Antarmuka IKeyStore