Share via


How to: Create IntelliSense Scripts

You can create IntelliSense scripts for items in the IntelliSense table. Creating IntelliSense scripts make it possible for commands, functions, or properties to run certain code, for example, to open a value editor when you want to assign values to certain properties. For more information, see IntelliSense Table Structure.

The following sections describe different ways for creating and referencing scripts:

  • Creating or Referencing Scripts for Multiple Items

  • Referencing Scripts for Single Items

Creating or Referencing Scripts for Multiple Items

In the IntelliSense table, you can create Script record whose Data field contains a custom procedure or Visual FoxPro code that other IntelliSense records can run, or you can store code in the Data field of an item that runs for that item only. Though the Data field generally contains code that other IntelliSense records run, it can also store metadata used by scripts. The FoxCode parameter object passes this metadata automatically to a script. For details about the FoxCode object, see FoxCode Object Reference.

To create IntelliSense scripts that other IntelliSense records can run

  1. Open the IntelliSense table in the FoxCode.dbf file using the IntelliSense Manager or programmatically.

  2. Create a record in the IntelliSense table for a Script item.

  3. In the Abbrev field of the Script item, type the keyword that you want other records to use as part of the script reference for running the script.

  4. In the Data field of the Script item, type the Visual FoxPro code you want for other IntelliSense records to run.

    Note

    Code in the Data field must contain a PARAMETERS or LPARAMETERS statement to accommodate the FoxCode object reference. Each IntelliSense script must contain a parameter that IntelliSense passes to the FoxCode parameter object. The FoxCode parameter object contains metadata describing how the script was called, including the source record in the IntelliSense table. For more information, see the description for the Script item type in IntelliSense Table Structure.

  5. In the Cmd field of items that run the script, type a script reference, which encloses the script keyword from the Abbrev field of the Script item with opening and closing braces ({}).

For example, typing the following text in the Abbrev field of the Script item designates the text as the script keyword:

Picture

Inserting the following code in the Data field of the Script item displays the Open Picture dialog box:

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

Typing the following text, which is the script keyword enclosed with opening and closing braces ({}), in the Cmd field of other IntelliSense records designates the text as the script reference:

{picture}

To reference existing IntelliSense scripts from other IntelliSense records

  1. In the IntelliSense table, find the Script item you want to use.

  2. In the Abbrev field of the Script item, find the keyword that you want to use as part of the script reference.

  3. In the Cmd field of the IntelliSense record that runs the script, type the keyword from the Abbrev field in the Script item enclosed by opening and closing braces ({}).

Referencing Scripts for Single Items

Except in Typing and COM Component items, when the Cmd field of an IntelliSense record contains only opening and closing braces with no script keyword, typing the text in the Abbrev field of that item runs any code that exists in the Data field of the same item.

To create scripts for single IntelliSense records

  1. In the IntelliSense table, find the item you want to create a script for.

  2. In the Data field of the item, type the Visual FoxPro code you want the item to run.

  3. In the Cmd field of the item, type opening and closing braces ({}) without a space between them.

For example, the following table illustrates an example code in the Data field of a Command item that runs when IntelliSense functionality is activated for that Command item only.

Field Name Example

Type

C

Abbrev

NOW

Cmd

{}

Data

(Stored in a memo field)

LPARAMETERS oFoxCode

RETURN TRANSFORM(DATE( ))

See Also

Tasks

How to: Edit IntelliSense Records
How to: Restore the Default IntelliSense Table

Other Resources

Customizing IntelliSense in Visual FoxPro