Populated from a Table

Description

This topic describes the process of creating a property sheet that is bound to a table, and can support data entry and editing. This property sheet was created with the Property Sheet Builder in Action Scripting. See Property-Sheet Style Xdialog.

 Creating the Variables

  1. After selecting the "Display an Xdialog Box" action script, the designer created 6 variables.

    • ps2 - captures the output of the ((|#Designing_the_Property_Sheet_Dialog|Property Sheet dialog))

    • btnSave - saves the content of the controls on the property sheet

    • btnFirst - navigates to the first record in the table

    • btnPrev - navigates to the previous record in the table

    • btnNext - navigates to the next record in the table

    • btnLast - navigates to the last record in the table

 Designing the Property Sheet Dialog

To create the property sheet:

  1. The designer selected the ps2 variable.

  2. Set the Width to 80 characters and Height to 25 lines.

  3. Clicked Define Property-Sheet Dialog in the Style list to display the Initial Code tab of the Property Sheet Builder.

  4. Defined the following variables and Xbasic code. Note that the fields of the clients table are child elements of the ptr pointer variable. The Xbasic code reads the first record of the table and uses the .RECORD_TO_VARS()method to set the individual control values. The result is that the first record will appear when the dialog displays.

    dim ptr as P
    dim ptr.customer_id as c
    dim ptr.zip as c
    dim ptr.state as c
    dim ptr.city as c
    dim ptr.address2 as c
    dim ptr.address1 as c
    dim ptr.lastname as c
    dim ptr.firstname as c
    dim tbl as P
    tbl = table.open("clients")
    tbl.order("lastname")
    tbl.fetch_first()
    tbl.record_to_vars(ptr)
  5. The designer then placed the appropriate clients table fields into Edit controls on the Items tab. For example, the field labelled "Address 1" was bound to the variable p.address1.

  6. Clicked OK to conclude the property sheet design.

To create the Save Record function:

  1. The designer selected the btnSave variable, selected "Button" in the Style list, and clicked Define Button.

  2. Selected "Picture only" in the Button Style list.

  3. In the Image Name control click the 'pallet' icon, select the 'disk and pencil' icon, and clicked Insert.

  4. In the Button Action list selected "Run Xbasic".

  5. In the Xbasic edit control entered the following code. The PROPERTY_RECURSE_ASSIGN()function copies the values of the ptr dot variable to the tbl dot variable.

    tbl.change_begin()
    property_recurse_assign(tbl, ptr)
    tbl.change_end(.t.)
  6. In the After Action list selected "Keep Dialog Box Open".

To create the First Record function:

  1. The designer selected the btnFirst variable, selected "Button" in the Style list, and click Define Button.

  2. Selected "Picture only" in the Button Style list.

  3. In the Image Name control click the 'pallet' icon, select the '|<' button, and click Insert.

  4. In the Button Action list selected "Run Xbasic".

  5. In the Xbasic edit control entered the following code. The PROPERTY_RECURSE_ASSIGN()function copies the values of the ptr dot variable to the tbl dot variable.

    tbl.fetch_first()
    tbl.record_to_vars()
  6. In the After Action list selected "Keep Dialog Box Open".

To create the Previous Record function:

  1. The designer selected the btnPrev variable, selected "Button" in the Style list, and clicked Define Button.

  2. Selected "Picture only" in the Button Style list.

  3. In the Image Name control click the 'pallet' icon, select '<', and click Insert.

  4. In the Button Action list selected "Run Xbasic".

  5. In the Xbasic edit control entered the following code. The PROPERTY_RECURSE_ASSIGN()function copies the values of the ptr dot variable to the tbl dot variable.

    tbl.fetch_prev()
    tbl.record_to_vars()
  6. In the After Action list selected "Keep Dialog Box Open".

To create the Next Record function:

  1. The designer selected the btnNext variable, selected "Button" in the Style list, and clicked Define Button.

  2. Selected "Picture only" in the Button Style list.

  3. In the Image Name control click the pallet icon, select the '>' icon, and click Insert.

  4. In the Button Action list selected "Run Xbasic".

  5. In the Xbasic edit control entered the following code. The PROPERTY_RECURSE_ASSIGN()function copies the values of the ptr dot variable to the tbl dot variable.

    tbl.fetch_next()
    tbl.record_to_vars()
  6. In the After Action list selected "Keep Dialog Box Open".

To create the Last Record function:

  1. The designer selected the btnLast variable, selected "Button" in the Style list, and clicked Define Button.

  2. Selected "Picture only" in the Button Style list.

  3. In the Image Name control click the 'pallet' icon, select the >| button and click Insert.

  4. In the Button Action list selected "Run Xbasic".

  5. In the Xbasic edit control entered the following code. The PROPERTY_RECURSE_ASSIGN()function copies the values of the ptr dot variable to the tbl dot variable.

    tbl.fetch_last()
    tbl.record_to_vars()
  6. In the After Action list selected "Keep Dialog Box Open".

 

  1. After completing the button definitions, the designer clicked Next > to display the second screen of the Script Genie.

  2. The designer selected Customize Xdialog layout and modified the code from:

    {Region}
    ~Xdialog_heading~;
    {Endregion};
    {Region}
    ~ps2_label~:| ~ps2~;
    | ~btnSave~;
    | ~btnFirst~;
    | ~btnPrev~;
    | ~btnNext~;
    | ~btnLast~;
    {Endregion};
    {Region}
    ~Xdialog_Footer~;
    {Endregion};
    {line=1,0};
    ~OK_Button~ ~Cancel_Button~;

to the following. The result was to reposition the buttons below the property sheet.

{Region}
~Xdialog_heading~;
{Endregion};
{Region}
~ps2_label~:;
~ps2~;
{Endregion};
{region}
~btnSave~
|
~btnFirst~
~btnPrev~
~btnNext~
~btnLast~
{endregion};;
{Region}
~Xdialog_Footer~;
{Endregion};
{line=1,0};
~OK_Button~ ~Cancel_Button~;

 Finishing the Action Script

  1. The designer added a Title for the dialog, then clicked Next >, Next >, and Finish.

  2. Finally, the designer clicked Add New Action and selected "Xbasic" from the Category list and "In-Line Xbasic" from the Action list.

  3. The window contains the code necessary to close the table when the action script ends. This is:

    tbl.close()

Limitations

Desktop applications only

See Also