Metodo IKeyStore::GetKey (dbgmodel.h)
Il metodo GetKey è analogo al metodo GetKey in IModelObject. Restituisce il valore della chiave specificata, se presente nell'archivio chiavi o nell'archivio chiavi padre dell'archivio chiavi. Si noti che se il valore della chiave è una funzione di accesso alla proprietà, il metodo GetValue non verrà chiamato nella funzione di accesso della proprietà. Verrà restituito il IModelPropertyAccessor effettivo in un IModelObject. In genere un client chiamerà GetKeyValue per questo motivo.
Sintassi
HRESULT GetKey(
PCWSTR key,
_COM_Errorptr_opt_ IModelObject **object,
IKeyStore **metadata
);
Parametri
key
Nome della chiave per cui ottenere un valore
object
Il valore della chiave verrà restituito in questo argomento.
metadata
L'archivio metadati associato a questa chiave verrà restituito facoltativamente in questo argomento. Non è presente alcun utilizzo per i metadati di secondo livello. Questo argomento deve pertanto essere in genere specificato come Null.
Valore restituito
Questo metodo restituisce HRESULT che indica l'esito positivo o negativo. I valori restituiti E_BOUNDS (o E_NOT_SET in alcuni casi) indicano che la chiave non è stata trovata.
Osservazioni
esempio di codice
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.
}
}
}
Fabbisogno
Requisito | Valore |
---|---|
intestazione | dbgmodel.h |