Emulating the FileMaker Pro Book Object in 4D, Part II


ACI - Documentation Français English German ACI Technical Notes ACI Technical Notes, By Subject Back Previous Next Find

Emulating the FileMaker Pro Book Object in 4D, Part II

By Steve Hussey, CEO, Alto Stratus LLC

Technical Note 00-29

Technical Notes for Technical Notes for 00-06 June 2000

Introduction


FileMaker Pro uses a book object to navigate through records. Clicking on the top page moves back one record (unless you are at the first record), and clicking on the lower page takes you to the next record (unless you are at the last record). Clicking and dragging the tab slider allows you to move backwards and forwards through a selection of records (known in FileMaker Pro as the found set). This technical note implements similar behavior in 4D.

In a previous technical note we implemented a technique which precisely mimicked FileMaker Pro's behavior. In this technical note we will implement a simpler technique which utilizes 4D's ruler object.

Ruler Objects


4D has a ruler object. The appearance of this is shown below (the variable name in this example is "rule_SlideMe").

The position of the tab can be set in two ways:

— The position can be set programmatically. The minimum and maximum values (the scale) is set, and then the position of the tab is set using that scale. For example, if the minimum value is 1, the maximum 500 and the variable rule_SlideMe is set to 250, the tab will appear half way along the ruler. The scale can be changed at any time. (The physical length of the ruler does not change, only the scale.) A minimum of 1, a maximum of 800 and rule_SlideMe = 400 will also position the tab in the middle.

— The user can drag the tab. The relative position of the tab on the ruler is passed to the variable rule_SlideMe for the ruler object. For example, for the ruler object rule_SlideMe, dragging the tab to the middle position will set the value of rule_SlideMe to 250.

Behavior of the FileMaker Pro Book Object


The picture above shows the standard view of the FileMaker Pro book object:

— In this example there are five records in the database, and five in the found set.

— The user is displaying the fifth record.

— The bottom page is disabled, since the current record is the last record in the found set.

— The top page is enabled, to allow the user to step back through the found set.

— The tab slider is at the bottom of the book object. It can be dragged upwards to move backwards through the found set.

— The record count is at five.

— The records are not sorted (as indicated by the "Unsorted" status).

The behavior of the book object changes slightly when there is a found set that is smaller than the number of records in the database. In the picture above, note the addition of the "Found:" count. Again the status indicates that the found set is unsorted. If the records are sorted, the text changes to "Sorted." The user is at record one of the found set, which contains two records in a database of six records.

In the picture above, the book object is displayed in the middle of a found set. Both the top and bottom pages are enabled, and the tab slider is in an intermediate position. The user is at record three of the found set (which is all records).

Why keep the book object in 4D?

If you have converted a FileMaker Pro database to 4D, you may want to keep some of the FileMaker Pro features, such as the book object, to maintain visual and behavioral consistency for the user.

4D does not have any similar objects, but the book object can be emulated with code and a few graphic objects and invisible buttons.

Using the Sample Book Object in 4D


Launch the sample database. To use the book object on a found set of all records:

— Select List Zip Codes from the File menu.

— Double-click any record in the list.

— Click the top page of the book object (if the text is visible).

— Click the bottom page (if the text is visible).

— Drag the tab on the ruler.

Cancel.

Sort the selection using the Sort button. This displays the Order by... editor.

— Sort the selection.

— Double-click any record.

— Note the status values below the book object.

Cancel.

Create a subselection of records:

— Click, Shift+Click or Command+Click (Control+Click on Windows) any selection of records.

— Click the Subset button to make the selected records the current selection.

— Double-click any record.

— Note the differences in the status variables below the book object.

Type in a record number below the lower page. That record will be displayed (assuming that it falls within the range).

Creating the Book Object


The first stage is to create the book object. This can be achieved by taking a screen shot of the book object in FileMaker Pro. On Mac OS you can press Command+Shift-4, or use Flash-It (or a similar utility), and on Windows you can use PaintShop Pro. The book object graphic was then modified slightly in a graphics program to make it narrower:

The text icon is then copied:

(In FileMaker Pro up to v4, the text icon was black on white. In FileMaker Pro v5 it changed to light blue on white.) These parts can be put together as follows:

The text objects are placed over the top of the two "pages."

— The text pictures are given the Object Names of pict_Text_Back and pict_Text_Next. (This is done using the Object Properties palette.)

— The book object needs no name.

Next, two invisible buttons are placed over the two pages. These are sized to precisely fit over the two pages.

— The top button has an object method that calls the project method FMPB_Button_Back.

— The bottom button has an object method that calls the project method FMPB_Button_Next.

FMPB_Button_Back

   If (long_SlctRecNum_Crnt > long_SlctRecNum_First)
      PREVIOUS RECORD (Current form table->)
      long_SlctRecNum_Crnt := long_SlctRecNum_Crnt - 1  ` Decrement counter
      rule_SlideMe := 0 - long_SlctRecNum_Crnt
   End if
   
   FMPB_TextIcon_Updt   ` Update status of text icon

FMP_Button_Next

   If (long_SlctRecNum_Crnt < long_SlctRecNum_Last)
      NEXT RECORD (Current form table->)
      long_SlctRecNum_Crnt := long_SlctRecNum_Crnt + 1  ` Increment counter
      rule_SlideMe := 0 - long_SlctRecNum_Crnt
   End if
   
   FMPB_TextIcon_Updt   ` Update status of text icon

Creating the Ruler Object

Draw the ruler object on the detail form:

Set the object properties to any minimum, maximum and units. These will be overridden when the form loads:

By omitting the other values, the tick marks and labels are not shown.

The ruler object has an object method that calls the FMP_GotoSlctdRcrd project method.

Create the Record Counter Variable

The variable long_SlctRecNum_Crnt is created to display the current selected record number:

The variable has the following object method:

   If ((long_SlctRecNum_Crnt >= 1) & (long_SlctRecNum_Crnt <= long_RecCount_Slctn))
      GOTO SELECTED RECORD ([Zip_Code]; long_SlctRecNum_Crnt)
      rule_SlideMe := 0 - long_SlctRecNum_Crnt
      FMPB_TextIcon_Updt
      
   Else
      long_SlctRecNum_Crnt := Selected record number ([Zip_Code])
   End if

Variables can then be added to display the current record count and the sort status:

The variable text_SortState is placed on the form twice: but with two different object names. Depending on whether a selection is being displayed, the sort state text label can appear in one of two different positions. Although they will display the same variable by using two different object names, you can make either one visible or invisible. The top variable is long_RecCount_Table. The other record count (the third variable from the top) is the selection count.

The lines consist of four lines (two grouped pairs) named Line1, Line2, Line3 and Line 4. Lines 1 and 3 are gray, 2 and 4 are white.

Setting up the Form Method


The book object is placed on the detail form for any desired table. The form has a form method:

   Case of
      
      : (Form event = On Load )
         
            FMPB_Setup ` Sets up the record counters, text labels and variables etc.
         
   End case

FMPB_Setup

First all necessary variables need declaring, to be compiler friendly:

      ` Compiler declarations
      ` Record numbers
   C_LONGINT (long_SlctRecNum_First; long_SlctRecNum_Last; 
   long_SlctRecNum_Crnt; long_RecCount_Slctn; long_RecCount_Table)
      ` Indicates sort status
   C_TEXT (text_SortState; $Format)

To manage the states of the book object, you will need to know how many records there are in both the current table and the current selection:

      ` How many records in the selection?
   long_RecCount_Slctn := Records in selection (Current form table->)
      ` As opposed to how many records we have in the table...
   long_RecCount_Table := Records in table (Current form table->)

Current form table returns a pointer to the table that "owns" the current form. Dereferenced, this can be used to determine which table is being referred to. This means that the code will work with whatever form the book object is placed upon.

Next you will need to know the current selected record number:

      ` Get current record position relative to the selection
   long_SlctRecNum_Crnt := Selected record number (Current form table->)

This is the selected record number of the record the user has just double-clicked. The selected record number is used, since the user may be working with either all the records in a table or a subselection of records.

Now the selected record numbers of the first and last records in the selection are stored in variables:

      ` Position of first record in current selection
   long_SlctRecNum_First := 1

      ` Position of last record in current selection
   long_SlctRecNum_Last := long_RecCount_Slctn

If there is no more than one record in the selection, then the ruler is hidden, which is how FileMaker Pro handles the tab slider of its book object:

   If (long_RecCount_Slctn <= 1)
      SET VISIBLE (rule_SlideMe; False)
   Else
      SET VISIBLE (rule_SlideMe; True)

The next step is to build the format string to set the ruler scale and tab position. A little known feature of rulers is that they can be formatted by passing the format values in a string, for example:

      SET FORMAT (rule_MyRuler; "Min;Max;Unit;Steps;Flags;Format")

This would translate, for example, into:

      SET FORMAT (rule_MyRuler; "1;500;10;10;10;#,##0" )

The format values have to be passed as explicit numerical values. They cannot be passed as variables. Therefore the format string has to be created first:

         ` Build the format string
      $Format := String (0 - long_SlctRecNum_Last) + ";" 
      + String (0 - long_SlctRecNum_First) + ";" + String (long_RecCount_Slctn) + ";1"

Since 4D's vertical ruler scale starts with the lowest value at the bottom and the highest value at the top, which is the opposite direction that the tab slider of FileMaker Pro's book object runs, the range of the ruler's scale is set here using negative numbers. This format string is then passed to the SET FORMAT command:

      SET FORMAT (rule_SlideMe; $Format )
         ` Set the ruler's tab to the current record position
      rule_SlideMe := 0 - long_SlctRecNum_Crnt
   End if

Now the other variables need to be calculated or set:

   If (long_RecCount_Slctn = long_RecCount_Table)  ` Then we are displaying all records
      SET VISIBLE (*;"Found"; False)  ` Turn off "Found" status label...
      SET VISIBLE (long_RecCount_Slctn; False)  ` Turn off Found counter
         ` Turn off the shaded lines - each is a pair - one gray - one white - grouped 
      SET VISIBLE (*;"Line1"; False)  
      SET VISIBLE (*;"Line2"; False)
      SET VISIBLE (*;"Line3"; False)
      SET VISIBLE (*;"Line4"; False)

By giving the variables two different names, you are able to turn off either one (without affecting its value).

         ` Turn on the "Sort" status label in the upper position
      SET VISIBLE (*; "Sort_Upper"; True)
         ` Turn off the "Sort" status label in the lower position
      SET VISIBLE (*; "Sort_Lower"; False)
   Else   ` We are displaying only a subselection of the records

In this case we are displaying a subselection of records:

      SET VISIBLE (*; "Found"; True)  ` Turn on "Found" status label
      SET VISIBLE (long_RecCount_Slctn; True)  ` Display Found count
         ` Turn ON the shaded lines - each is a pair - one gray - one white - grouped 
      SET VISIBLE (*; "Line1"; True) 
      SET VISIBLE (*; "Line2"; True)
      SET VISIBLE (*; "Line3"; True)
      SET VISIBLE (*; "Line4"; True)
         ` Turn OFF the "Sort" label in the upper position
      SET VISIBLE (*; "Sort_Upper"; False)  
         ` Turn ON the "Sort" label in the lower position
      SET VISIBLE (*; "Sort_Lower"; True)  
   End if

Now the text icons need to be made visible or invisible depending on the user's position within the selection:

      ` Update the text icon according to the position of the current record
   FMPB_TextIcon_Updt

The FMPB_TextIcon_Updt method sets the text icons visible or invisible depending on the position of the record the user selected:

      ` There are no existing records/selection/new record
   If ((long_RecCount_Slctn < 2) | (long_RecCount_Table < 2) | 
   (Record number (Current form table->) = New record))
      SET VISIBLE (*; "pict_Text_@"; False)  ` Turn off both text icons
   End if
      ` User is at first record
   If ((long_SlctRecNum_Crnt = long_SlctRecNum_First) & (long_RecCount_Slctn > 1))
      SET VISIBLE (*; "pict_Text_Back"; False)  ` Turn off upper text icon
      SET VISIBLE (*; "pict_Text_Next"; True)  ` Turn on lower text icon
   End if
      ` User is somewhere in the middle...
   If ((long_SlctRecNum_Crnt > long_SlctRecNum_First) & 
   (long_SlctRecNum_Crnt < long_SlctRecNum_Last)) 
      SET VISIBLE (*; "pict_Text_Back"; True)  ` Turn on upper text icon
      SET VISIBLE (*; "pict_Text_Next"; True)  ` Turn on lower text icon
   End if
      ` User is at last record
   If ((long_SlctRecNum_Crnt=long_SlctRecNum_Last) & (long_RecCount_Slctn > 1))
      SET VISIBLE (*; "pict_Text_Back"; True)  ` Turn on upper text icon
      SET VISIBLE (*; "pict_Text_Next"; False)  ` Turn off lower text icon
   End if

FMP_GotoSlctdRcrd Project Method


The FMP_GotoSlctdRcrd project method is called by the object method of the ruler object. As you drag the ruler's tab, its position is tracked and the value of rule_SlideMe is updated when you release the mouse button. This value corresponds to the relative position within the current scale, since the scale has been set to the size of the current selection. To compensate for the fact that dragging 4D's ruler increases its value in the opposite direction of FileMaker Pro's tab slider, negative numbers are used along the ruler's range. The Abs function now converts the negative value into the current selected record position:

   long_SlctRecNum_Crnt := Abs (rule_SlideMe)

The converted ruler position is then used to move to the corresponding record:

   GOTO SELECTED RECORD ([Zip_Code]; long_SlctRecNum_Crnt)

The text icons are updated:

   FMPB_TextIcon_Updt

Summary


While this method is similar to the FileMaker Pro book object, it is not exactly the same. However, due to 4D's implementation of the ruler object, the code is much simpler and the movement of the tab is smoother.


ACI - Documentation Français English German ACI Technical Notes ACI Technical Notes, By Subject Back Previous Next Find