To create a new script, click the Create button () when the Scripts panel is selected; alternatively, you can click the drop-down arrow beside the Create button and choose Create Script from the menu, or choose Create Script from the Objects or shortcut menus.

Either enter a custom name for a user-defined script or select the name of an event script from the drop-down list. To create a data object script, click the appropriate link in the properties pane when the data dictionary object is selected. The default language for the script is the same used last time you created a script. When you choose a language, the code is automatically filled in with a sample in the selected language if you select an event or data object script.

Stonefield Query supports link actions. In the Link page of the Field Properties dialog, the user can select what action to take when they click the selected field in the Preview window. There are three built-in actions: Email, which launches their email program with an email address filled in; Web site, which navigates their browser to a specific URL; and Report, which runs the specified report. You can also define custom actions. For example, perhaps you want another application to display the record for the customer name the user clicks in the Preview window. In that case, you have to tell Stonefield Query how to perform that action. That's where link action scripts come in. If you turn on the Link action setting for a script, Stonefield Query automatically includes the description contained in the Description setting in an Action drop-down list in the Link page of the Field Properties dialog. So, to continue this example, create a script that calls another application and tells it to display the record for the current customer name. Turn on the Link action setting for this script and set its Description setting to something like "Display customer information." The user can then select the customer name field in a report, select Action as the link type, and choose "Display customer information" from the Action drop-down. When they run the report, clicking the customer name calls your script, which does the necessary tasks to display the selected customer's record.

Note that the code for a link action script must accept two parameters. The first is a field name and the second is the value of that field in the record the user clicked. Your code can do anything it wishes with these parameters, except if the first parameter is blank, this is a "discovery" call from the Field Properties dialog. In that case, the second parameter contains the name of the field the link is on and the script must return a comma-delimited list of field names. By default, these fields will appear in the Action Parameter drop-down list in the dialog so the user can select one. If the field the user selects is not already in the query, it is automatically added with the Display this field in the report option turned off so it doesn't display in the report. If all of the fields in the returned list are required, prefix the list with "*,". In that case, the Action Parameter drop-down list doesn't appear and all fields are added to the query if they aren't already in it.

Here's an example of such a script:

lparameters tcFieldName, tuValue
if empty(tcFieldName)
  return 'Customers.CompanyName'
* do whatever is necessary

For another example, see the Linking to Google Maps topic.

Code Editing Window

You can enter code in the text box in Stonefield Query Studio, but it's more convenient to open an editing window; in addition to a larger editing area, you can take advantage of Stonefield Query's IntelliSense feature to speed code entry. To do so, right-click in the text box and choose Zoom from the shortcut menu. You can open multiple code editing windows at a time.

The code editing window can be moved and sized as desired. The shortcut menu for the window has the following functions:

  • Cut, Copy, and Paste: the normal Windows editing functions

  • Build Expression: displays the Expression Builder.

  • Font: allows you to select the font for the code.

  • Find: display a dialog allowing you to locate text in the code.

  • Go to Line: jumps to the specified line number.

  • Indent: moves the selected code to the right one tab stop.

  • Unindent: moves the selected code to the left one tab stop.

  • Comment: comments out the selected code by adding "!" at the start of the line.

  • Uncomment: uncomments out the selected code by removing "!" from the start of the line.

  • Make Uppercase: upper-cases the selected code.

  • Make Lowercase: lower-cases the selected code.

  • Properties: display the Properties dialog where you can specify properties of the window, such as whether indenting code uses spaces or tabs (let's not start THAT religious war here!) and what the indent size is.

Code is auto-indented as you type it. For example, if you are typing a line that's indented one tab, pressing Enter keeps that indentation on the next line.


Stonefield Query includes IntelliSense support for native Visual FoxPro language elements such as Visual FoxPro commands and functions, and for objects in the Stonefield Query object model.

There are several aspects to IntelliSense:

  • automatic keyword completion

  • command and function syntax tips

  • syntax coloring

  • lists of members and values

Automatic Keyword Completion

Automatic keyword completion means you can type just enough of a keyword to make it distinct, and then press Space or Enter in the case of a command or "(" in the case of a function, and IntelliSense completes the keyword for you. For example, if you type "subs(", IntelliSense replaces it with "substr(." Because some keywords start with the same set of characters, be sure to type enough to distinguish the keyword from any others. If you want to use the MessageBox() function, you can't just type "mess(;" IntelliSense expands that to "message(."

Some commands actually consist of more than one keyword; examples include Alter Table, Report Form, and Open Database. Since the first keyword must always be followed by the second, IntelliSense automatically adds that keyword as well.

"Set" is the first keyword in a long list of Set commands. When you type "set" and press Space, IntelliSense displays a list of each of the keywords that can follow "set," such as "deleted" and "exact."

IntelliSense doesn't complete keywords in the middle of a statement. For example, if you type the While clause of a Replace command as "whil," that's how it stays; IntelliSense won't expand it to "while."

Command and Function Syntax Tips

After typing "repl" and pressing Space, you may notice something besides the keyword completion: a tip window showing the complete syntax of the Replace command. This feature is called "Quick Info."

The tip window stays on-screen as you continue to type the rest of a command or enter the parameters of a function, method, or event, only disappearing when you complete the function with ")," move to another line (such as pressing Enter), or press Backspace (in that case, it reappears when you move the cursor to the next element of the command). You can manually hide it by pressing Esc.

For some functions, the tip window displays information about the values for a specific parameter. For example, the second parameter for MessageBox() is an additive value for the buttons and icon for the dialog. IntelliSense shows the complete list of valid values for this parameter.

Syntax Coloring

You can see in the image above that certain words appear in blue. These are Visual FoxPro commands and functions. Syntax coloring makes it obvious when you have correctly typed a keyword; if a keyword doesn't appear in blue, you haven't spelled it correctly.

Lists of Members and Values

Because you may frequently use members of Stonefield Query objects in scripts, the IntelliSense List Members feature does more to save you typing than any other. When you enter the name of an object and press ".", IntelliSense displays a list of all members (properties, methods, events, and contained members) of the object. For example, Stonefield Query passes a reference to the Stonefield Query Application object to event scripts:

lparameters toApplication as SQApplication

Since the parameter toApplication is specified to be an instance of the SQApplication object, when you type "toApplication" followed by a period, IntelliSense displays the members of the SQApplication object.

Other objects may be passed as well; in the above image, a Database object is passed in the toDatabase parameter, so you can type "toDatabase" followed by a period to see a member list for that object.

You can get IntelliSense for objects that aren't passed to a script by declaring that a variable is of a particular object type. For example, after typing this code:

local loField as Field, loTable as Table

you can enter "loField" and a period to see the members of the Field object or "loTable" followed by a period to see the members of the Table object.

You can navigate through the list using the up and down arrow keys, the Page Up and Page Down keys, or using incremental searching by typing the first few letters of a member's name (the letters you type also appear after the period in the command line). As you do so, a ToolTip box shows the description of each member, saving you a trip to the Help file.

IntelliSense adds the selected member's name to the command line and hides the list if you press Tab (the cursor appears right behind the member name), Enter (the cursor moves to the next line), or some non-alphabetical character such as Space, ".", "=", or "(" (the character is added at the end of the member name). Pressing Home, End, Esc, or the left or right arrow (if they move the cursor before the period or past the end of what's already typed) hides the list without adding the member's name to the command line.

List Members works in object hierarchies too. For example, if you type "toApplication.DataEngine.Fields.", you'll get IntelliSense after each period.

Some object properties accept only a small range of values. For example, the Reportable property of Table and Field objects is Boolean, so the only acceptable values are True (.T.) and False (.F.). The JoinType property of Join objects is 0 for inner join, 1 for right outer join, 2 for left outer join, and 3 for full join. IntelliSense makes it easy to select the correct value for properties like these. When you type "=" after some property names, IntelliSense displays a list of the valid values for those properties.

© Stonefield Software Inc., 2023 • Updated: 02/18/16
Comment or report problem with topic