//AB/ Project test autoincrement //AB/ Object prj is a View_Project //AB/ Set Size to 230 325 //AB/ Set ProjectName to "test autoincrement" //AB/ Set ProjectFileName to "TestAutoIncrement.vw" //AB/ Set GenerateFileName to "NONAME" // Project Object Structure // oNewView is a dbView // oButton1 is a Button // Register all objects Register_Object oCheckitButton Register_Object oAutoIncrCheckerView //AB-StoreTopStart Use Customer.DD //AB-StoreTopEnd //AB-IgnoreStart Use dfClient.pkg Use Windows.pkg //AB-IgnoreEnd DEFERRED_VIEW Activate_oAutoIncrCheckerView FOR ; ; Object oAutoIncrCheckerView is a dbView Set Border_Style to Border_Thick Set Location to 2 2 Set Size to 200 300 //AB-DDOStart //AB-DDOEnd Object oCheckitButton is a Button Set Label to "Check It" Set Location to 123 126 //AB-StoreStart Procedure OnClick Handle hoDD Get Create U_Customer_DataDictionary To hoDD If (hoDD > 0) Begin Send DoCheckDD hoDD Send Destroy Of hoDD End End_Procedure // OnClick Procedure Error_Report Integer iError Integer iErrLine String sErrMsg // Ignore all errors End_Procedure // Error_Report Procedure DoCheckDD Handle hoDD Integer iSourceFile iSourceField iDestField Integer iMainFile iIndex iLastId iCurrentId Integer iLastIdVal Handle hoErr Boolean bOpenedBefore bOpened bIsRecnum bEof bIsSystemFile Get Auto_Increment_Source_File Of hoDD To iSourceFile If (iSourceFile > 0) Begin Get Auto_Increment_Source_Field Of hoDD To iSourceField If (iSourceField > 0) Begin Get Auto_Increment_Dest_Field Of hoDD To iDestField If (iDestField > 0) Begin // Change the error handler object Move Error_Object_Id To hoErr Move Self To Error_Object_Id Get_Attribute DF_FILE_OPENED Of iSourceFile To bOpenedBefore If (Not (bOpenedBefore)) Begin Open iSourceFile End Get_Attribute DF_FILE_OPENED Of iSourceFile To bOpened If (bOpened) Begin Get Main_File Of hoDD To iMainFile Get_Attribute DF_FILE_IS_SYSTEM_FILE Of iSourceFile To bIsSystemFile If (bIsSystemFile) Begin Get_Attribute DF_FIELD_INDEX Of iMainFile iDestField To iIndex If (iIndex > 0) Begin Send Clear Of hoDD Send Find Of hoDD Lt iIndex If (HasRecord (hoDD)) Begin Get Field_Current_Value Of hoDD iDestField To iLastId End End Else Begin Get_Attribute DF_FILE_RECNUM_TABLE Of iMainFile To bIsRecnum If (bIsRecnum) Begin Move 0 To iIndex End Else Begin Get_Attribute DF_FILE_PRIMARY_INDEX Of iMainFile To iIndex End Move -999999999 To iLastId Send Clear Of hoDD Repeat Send Find Of hoDD Gt iIndex Move (Not (Found)) To bEof If (Not (bEof)) Begin Get Field_Current_Value Of hoDD iDestField To iCurrentId Move (iCurrentId Max iLastId) To iLastId End Until (bEof) End Get_Field_Value iSourceFile iSourceField To iLastIdVal If (iLastIdVal <> iLastId) Begin Send Stop_Box "The values don't match, code here what you need to reset the counter, for example the last id in the systemfile" End End Else Begin // Code for situation that counter comes from parent record End End If (Not (bOpenedBefore)) Begin Close iSourceFile End // Reset the error object id to it's original value Move hoErr To Error_Object_Id End End End End_Procedure //AB-StoreEnd End_Object // oCheckitButton CD_End_Object // oAutoIncrCheckerView //AB-StoreStart //AB-StoreEnd //AB/ End_Object // prj