----------------------------------------------
Using Stonefield Data Dictionary with Codebook
----------------------------------------------

This document describes how to replace the data dictionary included with the
FoxPro Codebook by Yair Alan Griver with the Stonefield Data Dictionary.

A few Codebook files will be changed, so we recommend that you first make a
backup copy of these files.

To start making these changes, make the directory that contains your project
file the default directory.

-----------------
1.  Edit MAIN.MNX
-----------------

* Replace the following code in the SETUP snippet:

    DO OPENDBF

with:

    glOPENERR = not OPENFILE()
    do OPENDB

* Cut the following three lines of code from the OPENDBF procedure in the
CLEANUP snippet:

    PUBLIC ARRAY gaStates[1]
    SELECT * ;
        FROM STATES ;
        ORDER BY States.cFullName ;
        INTO ARRAY gaStates
    SET ORDER TO TAG cState IN States

and paste them just before the following line near the start of the CLEANUP
snippet:

    WAIT CLEAR

* Remove the rest of the code for the OPENDBF procedure from the CLEANUP snippet.

* In the procedure for the Order bar in the Database pad, replace:

    DO GETORDER.SPR

with:

    do SORTER.SPR

* In the procedure for the Reindex bar in the Database pad, replace:

    DO DBFREIND.SPR

with:

    do REINDEX.SPR
    do OPENDB

* Remove the Compress bar from the Database pad.

-------------------
2.  Edit OPENDB.PRG
-------------------

* Remove all code except the following lines (note: you must add the "select
  SECURITY" line):

    IF USED("Security")
        select SECURITY
        SET FILTER TO cUSERID = m.gcUserID
    ENDIF
    *-- Set up cursor for window tracking
    IF !USED("SaveStat")
        CREATE CURSOR SaveStat ;
            (cWindow C(10), mMemvars M(10), cSaveID C(9), ;
            cOldAlias C(10), cOldOrder C(10) )
    ENDIF

--------------------
3.  Edit METHODS.PRG
--------------------

* To use the data-driven BROWSER routine when the user selects the List
  function, replace all of the code in the LISTIT procedure with:

    if BROWSER()
        scatter memvar memo
    endif BROWSER()

* To use the Stonefield relational integrity routines when deleting a record,
  edit the following code in DELETEIT:

    IF (IsLocked() OR RLOCK() OR NetLock()) AND DelRec()
        jcErrMsg = "Someone has modified this data. Do you want to delete " + ;
            "this information anyway? Doing so will destroy the other " + ;
            "person's changes. "

        IF cLastUpd # m.cLastUpd AND !AreUSure(jcErrMsg)
            WAIT WINDOW TIMEOUT 2 "Refreshing Other User's Changes..."
            SCATTER MEMVAR MEMO
        ELSE
            DELETE
            UNLOCK
            IF jnNextRec = -1               && Go to next record
                GO BOTTOM
            ELSE
                GO jnNextRec
            ENDIF
            SCATTER MEMVAR MEMO
            WAIT WINDOW NOWAIT "Information Deleted"
        ENDIF
    ENDIF

to read:

    do case
        case not (IsLocked() OR RLOCK() OR NetLock())
        case not CANDEL()
            do ERROR with 'This record cannot be deleted.'
        case DELREC()
            jcErrMsg = "Someone has modified this data. Do you want to delete " + ;
                "this information anyway? Doing so will destroy the other " + ;
                "person's changes. "
            IF cLastUpd # m.cLastUpd AND !AreUSure(jcErrMsg)
                WAIT WINDOW TIMEOUT 2 "Refreshing Other User's Changes..."
                SCATTER MEMVAR MEMO
            ELSE
                = DODEL()
                UNLOCK
                IF jnNextRec = -1               && Go to next record
                    GO BOTTOM
                ELSE
                    GO jnNextRec
                ENDIF
                SCATTER MEMVAR MEMO
                WAIT WINDOW NOWAIT "Information Deleted"
            ENDIF
    endcase

--------------------
4.  Edit APPSRCH.SCX
--------------------

* Replace the following code in the SETUP snippet:

    IF FCOUNT("Datadict") = 8               && Codebook 2.0
        SELECT Field_Name, Field_type, Field_Len, Field_Dec, cTag ;
            FROM Datadict ;
         WHERE DBF_Name = ALIAS() ;
            INTO ARRAY laFields
    ELSE
        SELECT Field_Name, Field_type, Field_Len, Field_Dec, cTag ;
            FROM Datadict ;
         WHERE DBF_Name = ALIAS() ;
           AND lShow ;
            INTO ARRAY laFields
    ENDIF

with:

    lcALIAS = alias()
    SELECT Field_Name, Field_type, Field_Len, Field_Dec, FIELD_DESC ;
        FROM Datadict ;
     WHERE FILE = lcALIAS ;
       AND REPORT ;
        INTO ARRAY laFields

-------------------------------
5.  Convert the Data Dictionary
-------------------------------

* Type the following:

    set default to DBFS
    set path to <SDD>\DATADRIV
    do TRANSFER
    set default to ..\

where <SDD> is the name of the directory where the Stonefield Data Dictionary
source code is installed. After the transfer is complete, you may delete the
following files from the DBFS directory if you wish:

	DD.DBF
	DD.FPT
	TABLDICT.DBF
	TABLDICT.FPT

* Bring up Stonefield Data Dictionary by selecting Data Dictionary from the
  Dictionary pad in the menu bar. When you are asked to locate the data
  dictionary files, select the DBFS directory. Ensure that Directory and Runtime
  Directory are set properly for all tables (Directory will contain ..\ and
  Runtime Directory will be blank for all tables located in the project
  directory).

* Add the following tables to the data dictionary (all are located in the
project directory):

    SETUP.DBF       ensure Auto Open is checked
    ONERROR.DBF     ensure Auto Open is checked
    SECURITY.DBF    ensure Auto Open and System are both checked

* In the Maintain Indexes screen, make the CMENUID tag the primary index for
SECURITY.DBF. Assign a primary index to all other tables.

* Define a list expression for each table.

* Define any relations as necessary.

---------------------------
6.  Update the Project File
---------------------------

* Remove the following objects from the project file:

    DATADICT                    Index
    DBFPACK                     Screen Set
    DBFREIND                    Screen Set
    GETORDER                    Screen Set
    PACKALER                    Screen Set
    TABLDICT                    Table/DBF
    TABLDICT                    Index

* Add the following objects to the project file:

    DBFS\FILEMAST.DBF           Table/DBF
    DBFS\INDXMAST.DBF           Table/DBF
    DBFS\RELATION.DBF           Table/DBF
    <SDD>\DATADRIV\REINDEX.SCX  Screen Set (ensure Modal is checked)
    <SDD>\DATADRIV\SORTER.SCX   Screen Set (ensure Modal is checked)
    <SDD>\DATADRIV\BROWSER.PRG  Program
    <SDD>\DATADRIV\INFO.BMP     File (only needed for Windows)
    <SDD>\DATADRIV\STOP.BMP     File (only needed for Windows)
    <SDD>\FILES25\JKEY.FLL      Library (only needed for Windows)
    <SDD>\FILES25\JKEY25.PLB    Library (only needed for DOS)

where <SDD> is the name of the directory where the Stonefield Data Dictionary
source code is installed.

---------------------
7. Update the Screens
---------------------

* You may optionally wish to use the DD GENSCRNX driver included with Stonefield
Data Dictionary when building your screens. If so, please see the README file
on your Stonefield Data Dictionary disk for instructions on using DD.

