Ever tried to find an easy way to make a copy of the current record in a datadictionary object? The old technique by putting a zero in recnum or setting DF_FILE_STATUS to DF_FILE_INACTIVE only works for the record buffer and does not fire the needed messages like Creating in the DDO. So I (finally) got tired to work around it and made this little procedure that takes the current record and prepare a new record with a copy of the data. It takes care of parent DDOs even if they are constained. This can be placed in a subclass of a datadictionary if you want to.
Call this procedure when you need a copy of the current record in the DDO. After you have called the procedure just change whatever field or parent DDO record needed to save the new record if any. This may be needed if any of your index requires it.Code:Procedure DoMakeNewCopy Integer iMaxField iCurField iDDFile iCurFile iMaxFile iParentFile Handle hParentDD RowID rwOld rwCurrentID RowID[] rwParents Boolean bFound String sData Get Data_Set_Server_Count to iMaxFile Decrement iMaxFile For iCurFile from 0 to iMaxFile Get Data_Set_Server iCurFile to hParentDD Get CurrentRowId of hParentDD to rwParents[iCurFile] Loop Get Main_File to iDDFile Get_Attribute DF_FILE_NUMBER_FIELDS of iDDFile to iMaxField Get CurrentRowId to rwOld Send Clear Move (FindByRowID(iDDFile, rwOld)) to bFound If bFound Begin For iCurFile from 0 to iMaxFile Get Data_Set_Server iCurFile to hParentDD Get CurrentRowId of hParentDD to rwCurrentID If (not(IsSameRowID(rwCurrentID, rwParents[iCurFile]))) Begin Get Main_File of hParentDD to iParentFile Send FindByRowId of hParentDD iParentFile rwParents[iCurFile] End Loop For iCurField from 1 to iMaxField Get_Field_Value iDDFile iCurField to sData Set Field_Changed_Value iCurField to sData Loop Clear iDDFile End End_Procedure
Remember to send Request_save when done.