How to Use the Caption Fields of a Table in a FormID: Q130997 3.00 WINDOWS The information in this article applies to:
SUMMARYVisual FoxPro's database offers some nice enhancements for developers. One such enhancement is the ability to use a table's caption property to hold the name of a field. Then you can reference the field caption property by using DBGETPROP to display the field description or name in a label on a form instead of having to enter this information manually in the caption property of the label.
MORE INFORMATIONThe premise behind this concept is this: Each field in a table has an associated caption property. This caption property can hold whatever text you would like to put in it, including the English text describing or naming the field.
Sample CodeThe following code demonstrates the behavior outlined in this article. The code has been documented so you can follow along when it executes. **========================================================** **========================================================**
SET SAFETY OFF
CLOSE ALL
CLEAR
CREATE DATABASE captest
CREATE TABLE cust (Cust_ID C(5), Cust_Name C(20))
INSERT INTO cust (Cust_ID, Cust_Name) Values ("00001","Acme Inc")
CLOSE ALL
OPEN DATABASE captest
USE cust
**--------------------------------------------------------** **--------------------------------------------------------**
=DBSETPROP("Cust.Cust_ID","FIELD","CAPTION","Customer ID")
=DBSETPROP("Cust.Cust_Name","FIELD","CAPTION","Customer Name")
**--------------------------------------------------------** **--------------------------------------------------------**
frmMyForm = CREATEOBJECT('Form')
frmMyForm.AutoCenter =.T.
**-------------------------------------------------------** ** This code adds the label and text box objects for the ** **-------------------------------------------------------**
frmMyForm.AddObject('lblCustID','lblCust_ID')
frmMyForm.AddObject('fldCustID','fldCust_ID')
**-------------------------------------------------------** ** This code adds the label and text box objects for the ** **-------------------------------------------------------**
frmMyForm.AddObject('lblCustName','lblCust_Name')
frmMyForm.AddObject('fldCustName','fldCust_Name')
**-------------------------------------------------------** **-------------------------------------------------------**
frmMyForm.AddObject('cmdQuit','cmdQuitButton')
CLOSE ALL
ERASE Cust.dbf
ERASE Captest.dbc
ERASE Captest.dbt
SET SAFETY ON
**-------------------------------------------------------** ** This is the class definition for the customer ID in- ** ** rived from the table itself. This is the example re- **
** its definition are stored together in the table. This **
** way, if you decide to change the name of the field in **
** the table, you can also just change the caption while **
** you're there and that change will be reflected on your**
**-------------------------------------------------------**
DEFINE CLASS lblCust_ID as label
ENDDEFINE
DEFINE CLASS fldCust_ID as textbox ENDDEFINE
**-------------------------------------------------------** **-------------------------------------------------------**
DEFINE CLASS lblCust_Name as label
ENDDEFINE
DEFINE CLASS fldCust_Name as textbox ENDDEFINE
DEFINE CLASS cmdQuitButton AS CommandButton && Create command button ENDDEFINE
Additional reference words: 3.00 VFoxWin Caption DBC KBCategory: KBSubcategory: FxtoolFormdes
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |