There is definitely a problem here. I see the crash also.
What happens is the added table appears to be already used in the selected workarea when you enter the dbc_AfterAddTable proc. The crash occurs if you reference that workarea. You can avoid the crash by adding a USE command at the top of the procedure to close the added table. Your code still doesn't work, though, because of a couple of other problems. For one (as I think someone else already pointed out), you can't add a table that is in use, so you have to add a USE between your CREATE and ADD TABLE commands.
More fundamentally, the ADD TABLE within the dbc_AfterAddTable will cause a recursion. This manifests itself as an "Alias name is already in use" error. If that didn't happen, I think you would hit the program stack limit of 128. I can't really tell what you are trying to accomplish, but I did report the crash as a bug. I'm not sure if the added table should be automatically opened, but either way it should not crash.
Thanks for bringing this to our attention!
>VFP8 crashes when I use a custom dbc event and would very much appreciate either confirmation or feedback as to what I am doing wrong.
>
>To duplicate...
>1) Create a small free table...
>CREATE TESTCRASH (F1 C(10), F2 C(5), F3 C(20))
>
>2) Create a new database.
>
>3) Modify the AfterAddTable event to contain the code below...
>
>PROCEDURE dbc_AfterAddTable(cTableName, cLongTableName)
>*After table is successfully added to the DBC.
>LOCAL lcTableAlias, lcStructure1, lcStructure2, lcStructure3, lcStructure4, oDataSession,;
> nCurrentSession, cSafeSetting
> cSafeSetting = SET('SAFE')
> SET SAFETY OFF
>*!* *nCurrentSession = SET('DataSession')
>*!* *oDataSession = CREATEOBJECT('Session')
>*!* *SET DATASESSION TO (oDataSession.DATASESSIONID)
>
> STORE SYS(2015) TO lcTableAlias
> STORE SYS(2015) TO lcStructure1
> STORE SYS(2015) TO lcStructure2
> STORE SYS(2015) TO lcStructure3
> STORE SYS(2015) TO lcStructure4
>
>SELECT 0
>CREATE CURSOR fldstru1 ( ID i AUTOINC, USERID CHAR(25), changedate T, postdate T)
>
>SELECT fldstru1
>COPY STRUCTURE EXTENDED TO (lcStructure1)
>
>SELECT 0
>USE (lcStructure1) ALIAS Structure1
>
>COPY STRUCTURE TO (lcStructure3)
>
>USE (cLongTableName) IN 0 AGAIN SHARED NODATA NOUPDATE ALIAS (lcTableAlias)
>
>SELECT (lcTableAlias)
>
>COPY STRUCTURE EXTENDED TO (lcStructure2)
>
>SELECT 0
>USE (lcStructure2) ALIAS Structure2
>
>SCAN
> COPY NEXT 1 TO (lcStructure4)
>
> IF NOT USED('Structure3')
> USE (lcStructure3) IN 0 ALIAS Structure3 EXCLU
> ENDIF
> SELECT Structure3
> ZAP
>
> APPEND FROM (lcStructure1)
> APPEND FROM (lcStructure4)
>
> CREATE ('TEST_FLD_'+ALLTRIM(Structure2.field_name)) FROM (lcStructure3) DATABASE (cDBC)
> ADD TABLE ('TEST_FLD_'+ALLTRIM(Structure2.field_name))
>ENDSCAN
>
>USE IN SELECT('Structure1')
>USE IN SELECT('Structure2')
>USE IN SELECT('Structure3')
>USE IN SELECT('Structure4')
>
>USE IN SELECT(lcTableAlias)
>USE IN SELECT(lcStructure1)
>USE IN SELECT(lcStructure2)
>USE IN SELECT(lcStructure3)
>USE IN SELECT(lcStructure4)
>
>ERASE (lcTableAlias+'.*')
>ERASE (lcStructure1+'.*')
>ERASE (lcStructure2+'.*')
>ERASE (lcStructure3+'.*')
>ERASE (lcStructure4+'.*')
>
>SET SAFETY &cSafeSetting.
>*SET DATASESSION TO nCurrentSession
>ENDPROC
>
>4) Turn dbc events on.
>
>5) Add TESTCRASH.DBF to the DBC
>
>
>Any comments would be MOST appreciated.
>
>Thanks,
>Larry Long
Jim Saunders
Microsoft
This posting is provided “AS IS”, with no warranties, and confers no rights.