KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Simulating Sub-Pages on Multi-Page Forms
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: July 1, 2009

Many developers implement their database UI via a multi-page form. It is common to have a form with a few basic pages, and then wanting to include a tab control or similar behavior on one of the pages. To do this you would need to nest pages. For example on page four of your form you would have sub-pages one, two, three and four. If you implement this with just one form, then you would need many pages. Each sub-page of page four of this theoretical situation would need to be its own page. This can be avoided by simulating sub-pages using multiple forms.

You can do this by making the original "form" actually a series of forms, where each page is its own form. Then the "pages" can each have their own sub-pages. Each form in the series would have a set of inherited data and form objects so they appear to be the same form, and then the tabs in the original form would set a CurrentPage variable and use VALIDATE or CANCEL to close the "page" and open another.

Here is an example of how it would work:

The setup:

  • 4 Forms named:
    • myform_page1
    • myform_page2
    • myform_page3
    • myform_page4

  • Each form has a tab control with the variable name mytab_var as shown here:



The implementation:
  • One method will be used to open your "form" (which is actually a compilation of forms). That method looks like this:
    C_LONGINT(CurrentPage;$win)
    C_BOOLEAN(CloseWindow)

    CurrentPage:=1
    CloseWindow:=False

    $win:=Open form window("myform_page1")

      `this method, "initAll", initializes the shared variables for "myform"
    initAll

    Repeat
        `this method, "initPage", initiates any page specific variables
      initPage(CurrentPage)
      DIALOG("myform_page"+String(CurrentPage))
    Until (CloseWindow)

    CLOSE WINDOW($win)


  • Each "page", which is in actuality a separate form, will have a form method that looks like this:
    Case of
      : (Form event=On Close Box )
        CloseWindow:=True
        CANCEL
    End case


  • Each tab control object will have an object method that looks like this:
    Case of
      : (Form event=On Clicked )
        CurrentPage:=mytab_var
        CANCEL
    End case


This way you can have each "page" actually be a separate form, then each "page" can have its own subpages handled as normal for forms and pages.

Commented by Thomas Fitch on July 17, 2009 at 9:51 AM
This Tech Tip isn't the only way to do "embedded" pages on forms. You can have one form with many pages. You just have to have a new page for every sub-page. In this example there is a 4 "page" form with subpages. You can do the same without using separate forms, for example:

Page 1 has 3 "subpages" so would actually take up pages 1, 2, and 3 of the form. (One for each different version of the page.) If none of your other pages had "subpages" then they would actually be pages 4, 5, and 6 instead of 2, 3, and 4.

This can lead to very many pages on a form, which is why the method outlined in this Tech Tip can help to simplify the situation. It also allows you to use page 0 for shared aspects of all subpages of page 1.