Metodo IModelObject::GetKey (dbgmodel.h)
Il metodo GetKey otterrà il valore di (e i metadati associati a) una determinata chiave in base al nome. La maggior parte dei client deve usare invece il metodo GetKeyValue. Se la chiave è una funzione di accesso alla proprietà, la chiamata a questo metodo restituirà la funzione di accesso alla proprietà (un'interfaccia IModelPropertyAccessor) in un IModelObject. A differenza di GetKeyValue, questo metodo non risolverà automaticamente il valore sottostante della chiave chiamando il metodo GetValue. Questa responsabilità è quella del chiamante.
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. In alcuni casi di errore, le informazioni estese sull'errore possono essere passate in questo argomento anche se il metodo restituisce un HRESULT non riuscito.
metadata
L'archivio metadati associato a questa chiave verrà restituito facoltativamente in questo argomento.
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> spProcess; /* get a process object */
ComPtr<IModelObject> spIdKey;
if (SUCCEEDED(spProcess->GetKey(L"Id", &spIdKey, nullptr)))
{
// Unlike GetKeyValue(), spIdKey may contain a value or it may be a
// *property* that needs to be fetched. Check!
ModelObjectKind kind;
if (SUCCEEDED(spIdKey->GetKind(&kind)))
{
if (kind == ObjectPropertyAccessor)
{
VARIANT vtProp;
if (SUCCEEDED(spIdKey->GetIntrinsicValue(&vtProp)))
{
// There is an *in-process* guarantee because of
// ObjectPropertyAccessor that the IUnknown is an IModelPropertyAccessor
IModelPropertyAccessor *pPropertyAccessor =
static_cast<IModelPropertyAccessor *>(vtProp.punkVal);
// Fetch the value underneath the property accessor. GetKeyValue
// would have done this for us.
ComPtr<IModelObject> spId;
if (SUCCEEDED(pPropertyAccessor->GetValue(L"Id", spProcess.Get(), &spId)))
{
// spId now contains the value of the id. Unbox with GetIntrinsicValueAs.
}
VariantClear(&vtProp);
}
}
else
{
// spIdKey contains the value. Unbox with GetIntrinsicValueAs.
}
}
}
Fabbisogno
Requisito | Valore |
---|---|
intestazione | dbgmodel.h |