These are some of the most frequently-asked questions about Visual FoxPro. Scan this list before you call Microsoft Technical Support. To print these notes, choose Print Topic from the File menu.
Question 1: How do I hide the Visual FoxPro desktop when my application's .EXE file starts?
Answer: Put the following line in the CONFIG.FPW configuration file:
SCREEN=OFF
Note: If you do not need to provide the CONFIG.FPW as a separate file-- that is, you will not need to be making any changes to it after building the .EXE--you can add the CONFIG.FPW file to the project, making sure it is marked as included, and it will be built it as part of the .EXE.
Question 2: How do I create a top-level form with a top-level menu?
Answer: To create a top-level form, set the form's ShowWindow property to 2-As Top Level Form. To create a top-level menu, open the Menu Designer. From the View menu, choose General Options, then set the Top-Level Form option. To place the top-level menu in the top-level form, put the following code in the Init event of the form:
DO <menu name.mpr> with THIS
Question 3: Some of the forms in the Solution sample files do not display label or control captions correctly. Why not?
Answer: The forms in the Solution sample are designed to display correctly with the Windows default font setting (small fonts). If you use large fonts, some of the forms will not be displayed correctly. To use small fonts, in the Control Panel double-click the Display icon, then in the Display dialog box, choose the Settings tab. In the Font Size drop-down list, choose Small Fonts.
Question 4: If I edit or run my Visual FoxPro 3.0 forms in Visual FoxPro 5.0, the fonts are smaller and no longer appear bold. Why does this happen and how can I avoid this?
Answer: To enable you to more easily make forms that comply with the Windows 95 standard, several default property settings for controls were changed, including FontSize, FontBold, and ColorSource. If these were set to default values under Visual FoxPro 3.0, they will remain defaults under Visual FoxPro 5.0. However, because the defaults are different, text will be displayed differently.
If you want to have your forms appear as they did in Visual FoxPro 3.0, convert them as part of a project. Then when you open the Visual FoxPro 3.0 project in Visual FoxPro 5.0, check the Retain Visual FoxPro 3.0 Default Property Values check box in the Converter.
Question 5: Why is this version called Microsoft Visual FoxPro 5.0 rather than Microsoft Visual FoxPro 4.0?
Answer: This was done to synchronize the Visual FoxPro version number with other Microsoft products such as Visual Basic.
Question 6: The Application Wizard does not appear when I select Wizards from the Tools menu. How do I run it?
Answer: To run the Application Wizard, choose Wizards from the Tools menu and then choose All from the submenu. This opens the Wizard Selection dialog box from which you can select the Application Wizard.
Question 7: Do I need to use the Join Source Control Project option on the Project menu every time I open a Visual FoxPro project that is under source control?
Answer: No, you do this only once. When you select Join Source Control Project, Visual FoxPro creates a copy of the existing project (.PJX) file on your local disk in the project's working directory. (Visual FoxPro also creates a project file list -- .PJM file, for "project metafile" -- which it uses to manage the changes made by different developers to the list of files in the project.) After you have joined a project, you can open the project as usual and Visual FoxPro will recognize that it is under source control.
Question 8: When I add a file to a Visual FoxPro project under source control I get the following error message:
"File <file name> could not be mapped to the SourceSafe project $/<project name>"
The preceding message is then followed by this message in the Source Control Results window:
"SCC API error 'Operation not performed' occurred on file <file name>."
The added file is not visible to other users sharing the project, even after I choose Update Project List. What am I doing wrong?
Answer: When adding files to a Visual FoxPro project under source control, save them to the working directory in which the copy of the current project was created.
Question 9: I just added a file to a Visual FoxPro project under source control and have added the file to source control as well, but it is not visible to other users sharing the project. What's wrong?
Answer: After creating a new file or adding a file to a project, you must update the project list file (.PJM file) so that the new or added file becomes visible to other users. From the Source Control submenu on the Project menu, choose Update Project List. Visual FoxPro then merges your local project file list with the one stored centrally. Other users must then also do the same. When they do, Visual FoxPro merges the changes with their local project list (.PJM) file and rebuilds their local project (.PJX) file.
Question 10: What is an offline view and what can I use it for?
Answer: An offline view allows you to get a snapshot of a table and manipulate it without having to be connected to the host table. When you are finished with the table, you can connect to the host again and synchronize the view with the host table. Using offline views, you can:
* Replicate a subset of data from Visual FoxPro table or a remote data source.
* Manipulate the replicated subset either interactively or through an application.
* Share a change buffer table while off line.
* Reconnect to the proper data source.
* Batch update the local or remote table(s).
These features can be very useful if you need to work with a small portion of data without being physically connected to its source -- for instance, when you are travelling or working offsite and you need to work with the most current data in a table.
Question 11: I am using the SYS(3054,1) function and it does not provide optimization info for a SQL statement using the JOIN clause. Why not?
Answer: Use 11 as the second parameter instead of 1.
Question 12: Using SQL, I am trying to create a Left Join out of multiple tables into one table. The query works if all the tables used by the query are open, but produces errors if some of the tables are not open. If all the tables are open, I do not get errors, but the results are not correct. Why not?
Answer: You are probably using a statement that attempts a Self Join using table aliases while trying to Left Join all the tables to one table. Your SQL statement might look like this:
select one.firstname as first, one.lastname as second,;
two.firstname as third, two.lastname as fourth;
from FirstTable;
left outer join SecondTable one;
left outer join SecondTable two;
left outer join ThirdTable;
on ThirdTable.ThirdID=FirstTable.FirstID
on Two.SecondID=FirstTable.FirstID
on one.SecondID=FirstTable.FirstID
order by 4,3,2,1
This query is trying Left Join the cursors One and Two, and the ThirdTable to FirstTable, but will not achieve the desired results. The query parser looks at this query starting from the innermost join (in this case would be "left outer join ThirdTable") and is not able to locate FirstTable table which is higher up in the statement. Therefore, if the tables are not open, you will see errors such as "SQL: Column 'ThirdID' is not found," and the output will not be correct.
When the tables are opened, "couple.coupleid" is bound to the field in the external (non-SQL) cursor called "couple." The query is then legal, but doesn't give the desired results. In order to avoid the error, and to get the correct results, you can use a SQL statement similar to the following:
select one.firstname as first, one.lastname as second,;
two.firstname as third, two.lastname as fourth;
from (((FirstTable;
left outer join SecondTable One;
on one.SecondID = FirstTable.FirstID);
left outer join SecondTable Two;
on Two.SecondID = FirstTable.FirstID);
left outer join ThirdTable;
on ThirdTable.ThirdID = FirstTable.FirstID);
order by 4,3,2,1
The parentheses in the statement are not necessary but are recommended. With the above statement structure you will not see errors even if the tables are closed, and the result set will be correct.
Question 13: When should I use object-oriented programming instead of procedural programming? Is it better to create classes visually or through program code?
Answer: You can continue to use a traditional procedural programming style in Visual FoxPro if you prefer it. Most FoxPro version 2.x programs coded in procedural style will run with only minor modifications in Visual FoxPro.
However, consider making the transition to an OOP programming style if the following conditions are true:
1. Your organization currently participates in a
structured, analytical process for new programming projects.
2. You are willing to invest the resources necessary to develop
a library of reusable code, without realizing full payback
on this investement until after the current project.
3. You want to tap the power of Visual FoxPro event handling,
common code syntax, and other benefits associated with OOP.
When you create a class programmatically, you must know all of the commands necessary to complete a task, but you can also inspect any portion of code at any time. If you create a class visually, you do not need to know all of the commands to complete a task, but you must look at each method individually. One of the benefits of Visual FoxPro is the ability to add a class defined through code to a form, save the instantiated objects as a class, and then edit those classes visually. This functionality, combined with the ability to export code through the Class Browser, provides the best of both types of class design tools.
Question 14: What is the difference between the DataSource property and the ControlSource property?
Answer: The DataSource property affects ODBC views stored in a database (.DBC). It contains a reference to the name of the data file to which ODBC is connecting, and must point to a valid data source defined through the ODBC administrator. You can manipulate the DataSource property with the SQLSETPROP( ) function and view its settings with the SQLGETPROP( ) function.
The ControlSource property is used to determine the source of data to which an object is bound; the table or view to which the object is bound can be of any type, including local Visual FoxPro tables. Objects that have a ControlSource property include the CheckBox, Column, ComboBox, CommandGroup, EditBox, ListBox, OLE Bound Control, OptionButton, OptionGroup, Spinner, and TextBox controls.
Question 15: How can I set properties for a form or for a command button in a command group?
Answer: Imagine that you are creating a form called Form1 that contains a command group named CommandGroup1, and two command buttons called Command1 and Command2. You can change the caption properties for all items except Command2 by setting the Caption property. For example, place the following code in the Click event of Command2:
Note: You can reference the current form using the generic reference THISFORM or using the form's explicit name. For more information, see Chapter 9, "Creating Forms," in Developer's Guide.
Question 16: Why is my combo box displaying only one row of data? I dimensioned an array for the combo box and issued a SELECT - SQL command in the Init event of my form to populate the array.
Answer: You created an array in the form's Init event with no rows or with only one row. When the form is created, the Init event of the combo box occurs before the Init event of the form, and the combo box therefore contains only one row of information. To fix this, add the following line of code immediately after the SELECT - SQL statement that creates the array in the form's Init event:
Question 17: How do I hide specific columns in a combo box and display others?
Answer: The easiest way to hide specific columns in a combo box is with the Combo Box Builder. Drag the columns to the desired width in the Layout tab of the Combo Box Builder.
To hide specific columns in a combo box programatically, set the ColumnWidth property to 0 for the columns. In the following program code, Columns 1 and 2 are hidden, and Column 3 has a width of 100 pixels:
THISFORM.ComboBox1.ColumnWidths = 0,0,100
Question 18: What is the difference between table buffering and referential integrity?
Answer: Row and table buffering can be used to directly update tables and records in a multiuser environment. This eliminates the need to place the data from a record into system variables, edit the system variables, check to see if the record has changed, and then write the changes to the record. For more information, see Chapter 17, "Programming for Shared Access," in the Developer's Guide.
In a relational database, referential integrity consists of the rules that govern the relationships between the primary and foreign keys of different tables. Referential integrity guarantees that all foreign keys match a value in the corresponding primary key field.
In addition to allowing Visual FoxPro to enforce rules that govern referential integrity, you can create stored procedures that perform specific actions when a record in a table is updated, deleted, or inserted. The Referential Integrity Builder can create stored procedures for each Update, Delete, or Insert trigger. The Visual FoxPro trigger types are listed below and the stored procedures available for each are listed in parentheses after the trigger type.
* Update (Ignore, Cascade, or Restrict)
* Delete (Ignore, Cascade, or Restrict)
* Insert...(Ignore and Restrict)
The names of stored procedures are inserted into each trigger in the Table Properties dialog box of the Table Designer. Triggers are typically stored as a part of the database's stored procedures (as the Referential Integrity Builder does), but can also be an external program or procedure. Triggers can be created programmatically with CREATE TRIGGER, or by adding a stored procedure to the database and referencing the stored procedure in the appropriate trigger in the Table Properties dialog box of the Table Designer.
Although triggers are typically used to implement (by using the Referential Integrity Builder) Cascade or Restrict capabilities on Update and Delete events, or Restrict capabilities on Insert events, these triggers can also be used to call stored procedures that perform actions unrelated to referential integrity. For example, an Update trigger could execute a stored procedure that sends an email message to another department to notify others of a change.
Referential integrity and buffering interact in the following way. Record-level event code is executed after a record is inserted, updated, or deleted. Triggers are executed after rules. However, when table or row buffering is in effect, triggers are not executed until the record (or records) are updated. (A record update occurs when the TABLEUPDATE( ) function is called or when the record pointer is moved while row buffering is in effect.)
Buffering and referential integrity can be used independently of each other, and the use of referential integrity does not require that buffering be used. In a multi-user environment, you would typically use buffering whether or not referential integrity is in use.
Question 19: Using Visual FoxPro 5.0 running on Windows 95, I created an .EXE file and used the Setup Wizard to make distribution disks. Now the application will not run on any Windows for Workgroups machines. Why is this?
Answer: Visual FoxPro 5.0 is a 32-bit application and will create only 32-bit .EXE files. Windows for Workgroups is a 16-bit operating system and can run only 16-bit applications. You need to have Windows 95 or Windows NT 3.51 or later to run your Visual FoxPro applications.
Question 20: Can I customize the colors used to mark syntax in an edit window?
Answer: You can easily customize how your code looks by choosing Options from the Tools menu and selecting the Syntax Coloring tab in the Option dialog box. There you will find a variety of ways to customize the coloring of your code.
If you would like to turn syntax coloring off completely, from the Edit menu choose Properties to display the Edit Properties dialog box. Then clear the Syntax Coloring check box.