And even that's simpler than it should be, particularly in the case of Nils's original problem in his CrossMerge application. The method in which the problem arose, with my suggested solution, is:It is likely that the first iteration of the loop will find a container object in which case iField will be zero. There is nothing within this method that says that iSearchField cannot be zero (i.e. Recnum) and if it is the function will return the handle to this container object which is obviously incorrect.Code:Function DDObjectId Global Handle hoDD Integer iFile String sField Returns Handle Handle ho Integer iField iCount iItems iSearchField Field_Map iFile (Trim(sField)) To iSearchField Get Data_Set_User_Interface_Count Of hoDD To iItems For iCount From 1 To iItems Get Data_Set_User_Interface of hoDD iCount to ho If (ho <> 0) Begin If (isTrapped(trappedErrors(Error_Object_Id), DFERR_BAD_MESSAGE)) Begin Send Ignore_Error to Error_Object_Id DFERR_BAD_MESSAGE Get Data_Field of ho to iField Send Trap_Error to Error_Object_Id DFERR_BAD_MESSAGE End Else Get Data_Field of ho to iField End If (iField = iSearchField) Break Loop // For iCount from 1 to iItems Function_Return ho End_Function // DDObjectId
So I think we need:Code:Function DDObjectId Global Handle hoDD Integer iFile String sField Returns Handle Handle ho Integer iField iCount iItems iSearchField Field_Map iFile (Trim(sField)) To iSearchField Get Data_Set_User_Interface_Count Of hoDD To iItems For iCount From 1 To iItems Get Data_Set_User_Interface of hoDD iCount to ho If (ho <> 0) Begin Move False to Err If (isTrapped(trappedErrors(Error_Object_Id), DFERR_BAD_MESSAGE)) Begin Send Ignore_Error to Error_Object_Id DFERR_BAD_MESSAGE Get Data_Field of ho to iField Send Trap_Error to Error_Object_Id DFERR_BAD_MESSAGE End Else Get Data_Field of ho to iField End If (not(Err) and iField = iSearchField) Break Loop // For iCount from 1 to iItems Function_Return ho End_Function // DDObjectId


Reply With Quote