共用方式為


Using Scripting in FoxCode.dbf

You can enhance significantly the design time functionality of Visual FoxPro by modifying the FoxCode.dbf. You can add your own procedures by changing field values or by adding Visual FoxPro code to the Data field of Script item types. You can create script items that provide code for any other item, or you can include code within an item that is specific to that record.

To enable scripting for any item

  1. Place a reference to the triggering keystrokes (from the Abbrev field) in the Cmd field of an item. A reference consists of the triggering keystrokes delimited by right and left braces as in this example:

    {picture}

  2. Copy the triggering keystrokes to the Abbrev field of the referenced Script item.

    To apply an existing script to this item, reference the Abbrev field contents of the Script item type record that contains the code you want to use in its Data field.

  3. Add appropriate Visual FoxPro code to the Data field of the script item as in the following example from the Data field of the Script item type referenced by the earlier Cmd field example:

    LPARAMETER oFoxcode
    LOCAL lcPicture
    oFoxcode.valuetype="V"
    lcPicture = getpict()
    IF LEN(lcPicture) > 0 
       lcPicture = ['] + lcPicture+ [']
    ENDIF
    RETURN lcPicture 
    

    You can access Script item types from any other item type by using this procedure, allowing one Script item to serve many other items.

In the following example, each item requires two records to enable its functionality – the calling item, which contains the reference information, and the Script item type, which contains the code to be run.

To enable scripting within an item type

  • Provide appropriate Visual FoxPro code in the Data field of the item record.

    This example uses the code in the previous Script item type in the Data field.

    LPARAMETER oFoxcode
    LOCAL lcPicture
    oFoxcode.valuetype="V"
    lcPicture = getpict()
    IF LEN(lcPicture) > 0 
       lcPicture = ['] + lcPicture+ [']
    ENDIF
    RETURN lcPicture
    

Data Fields and the FoxCode Object

The Data field generally contains script code to be executed by user-defined IntelliSense scripts. However, it can also be used just to store data used by scripts. This type of metadata is automatically passed to a script by the FoxCode parameter object.

For details about the FoxCode object, see FoxCode Object.

See Also

IntelliSense Overview | Customizing IntelliSense Using FoxCode | Visual FoxPro IntelliSense Manager Window | FoxCode Object