nsISupportsArray* value = nsnull; nsresult res = NS_NewISupportsArray(&value); if (NS_SUCCEEDED(res) && value) { PRInt32 j=0; PRInt32 i; for (i=0; i<mNumOptions; i++) { PRBool selected = PR_FALSE; res = GetOptionSelected(i, &selected); if (NS_SUCCEEDED(res) && selected) { nsISupportsPRInt32* thisVal = nsnull; res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_PROGID, nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)&thisVal); if (NS_SUCCEEDED(res) && thisVal) { res = thisVal->SetData(i); if (NS_SUCCEEDED(res)) { PRBool okay = value->InsertElementAt((nsISupports *)thisVal, j++); if (!okay) res = NS_ERROR_OUT_OF_MEMORY; } if (!NS_SUCCEEDED(res)) NS_RELEASE(thisVal); } } if (!NS_SUCCEEDED(res)) break; } if (i<mNumOptions) NS_RELEASE(value); } *aState = (nsISupports*)value; return res;
return NS_OK;
nsNativeSelectControlFrame::SaveState(nsIPresContext* aPresContext, nsISupports** aState){  nsISupportsArray* value = nsnull;  nsresult res = NS_NewISupportsArray(&value);  if (NS_SUCCEEDED(res) && value) {    PRInt32 j=0;    PRInt32 i;    for (i=0; i<mNumOptions; i++) {      PRBool selected = PR_FALSE;      res = GetOptionSelected(i, &selected);      if (NS_SUCCEEDED(res) && selected) {        nsISupportsPRInt32* thisVal = nsnull;        res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_PROGID,	                       nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)&thisVal);        if (NS_SUCCEEDED(res) && thisVal) {          res = thisVal->SetData(i);	  if (NS_SUCCEEDED(res)) {            PRBool okay = value->InsertElementAt((nsISupports *)thisVal, j++);	    if (!okay) res = NS_ERROR_OUT_OF_MEMORY; // Most likely cause;	  }          if (!NS_SUCCEEDED(res)) NS_RELEASE(thisVal);	}      }      if (!NS_SUCCEEDED(res)) break;    }    if (i<mNumOptions)      NS_RELEASE(value);  }  *aState = (nsISupports*)value;  // Set to null if not successful  return res;}