get_Item and Item, what sort of parameter?

Top  Previous  Next

When I need to get an item from a list, I generally use get_Item, because it crashes less, Item will throw an exception.

 

Here, the last two lines of code do the same thing:

 

  CComPtr<UserParameter> pUserParam ;

  pUserParameters->get_Item (CComVariant(i),&pUserParam) ;

  pUserParam = pUserParameters->Item [i] ;

 

And what about the parameters? Generally it is an index, and generally that index starts at 1 (not 0) as the first item.

 

   for (UINT i = 1 ; i <= ikNumModelParams ; i++) {

       CComPtr<ModelParameter> pModelParam ;

       pModelParameters->get_Item (CComVariant(i),&pModelParam) ;

 

Sometimes, if the item in the list has a text name, you can use the name in the call to get_Item. For example:

 

   const wchar_t* const pszUserParamName = ...

   ...

   CComPtr<UserParameter> pUserParam = nullptr ;

   pUserParameters->get_Item (CComVariant(pszUserParamName),&pUserParam) ;

 

Horses for courses.

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)