DOCUMENT #775 =========================================================================== WINDOWED FORMS =========================================================================== PRODUCT: R:BASE VERSION: 4.5+ or Higher =========================================================================== CATALOG: Forms, Reports & Labels AREA : Forms =========================================================================== Display multiple forms on the same screen using what are called windowed forms. The windowed form pops-up over the main form and then disappears when done. It can be used for display only, for adding data, for editing data. There are just a few simple commands in the EEP that calls the windowed form. The real key is in how the form is designed. You can't just call and pop-up any form; the form must be specifically designed to be a windowed form. Designing the windowed form The windowed form is called with the AT option to specify a starting row for the form display. A windowed form does not take up a full screen or page. Locate all the fields at the top of the form definition screen. Generally a windowed form will take up less than 10 lines of the screen. A windowed form does not need to be a single page form, but each page must be laid out the same in terms of field placement -- the fields are placed at the top of the page and each page uses approximately the same number of rows. The AT option controls the screen row on which the fields are displayed. The screen column location is determined by where the fields are located on the form. Thus, while fields are located starting on row one of the form definition, they aren't located starting in column one unless you want them to display at the extreme left of the screen when the form is used. Customize the Form settings of a windowed form as follows: Set Clear the screen before form use? to No. Set Clear the screen after form use? to Yes. Yes to Do you want to change the menu? for both Add data and Edit data. Select No menus. The key to creating a windowed form that looks like a pop-up window is to not locate any text on the form. The form contains field locations only. The reason you don't want any text typed on the form is that the text is stored as an 80 character line. When the form is displayed, the entire 80 character line is written, including any blank characters. You don't get the windowed effect when you have text located on the form. Region border lines, by the way, are stored as literal text. If your windowed form is a region, specify no border. You can use variables to place field headings and other textual information on the windowed form. Define a form expression, vtext = 'fieldname 1'', for example. Locate the variable, set the Field settings to make it non-editable, and it displays the defined text when the form is used. Alternatively. the EEP that calls the windowed form can write text to the screen at the appropriate locations. Because the windowed form does not clear the screen before it displays, the text stays on the screen. Calling the windowed form A windowed form is called through an EEP using the form-in-a-form feature of 4.5 and 4.5 Plus!. The main or calling form brings up the windowed form with the AT option of either the ENTER USING or EDIT USING command. The AT option specifies the screen row number where the first row of the form layout is displayed. Without the AT option, a form displays starting on row 2 of the screen; row 1 is reserved for the form menu. Often the clear screen command, CLS, is used to draw a colored box on the screen to highlight the windowed form display. This makes the form look even more like it is in a window. Don't put SCREEN RESTORE OFF in the EEP that calls the windowed form. You want the screen to restore to it's original look and display of before the EEP with the windowed form was run. An example Let's look at the Product form in the Concomp sample database. The form consists of three tables: Product, Compused and Prodlocation. It displays information about current products, what components are used in the product and all current product locations. Now, suppose, for example, that we don't want the current product locations always displayed on the form. We just want to see the product and its components initially, but display product locations if needed. We can call up and display the product locations using a windowed form. It requires just a few simple changes. 1. Split the Product form into two separate forms, the original form, still named Product, contains the Product and Compused tables. The second form, a new form named Prodloc, contains just the Prodlocation table. Remove the table Prodlocation from the form (you can do this on the Layout menu). That also removes all the locations for the table. Then just delete all the related text. The fields for the Product and Compused tables can be rearranged as desired. 2. Define a form expression to place the current model value into a variable, vmodel = model. This will be used by the EEP to call the windowed form to display the locations for that specific model only. 3. Locate a variable, vloc, to control when product locations are displayed. A mouse click or F2 on this field activates the EEP that displays the product location information in the windowed form. Define an expression for the variable to provide instructions, for example, vloc = 'Click for product locations'. Locate the variable wide enough for all the text to display. Customize the Field settings to make sure the variable is editable and to add an EEP On exit from field. The EEP calls the windowed form. The EEP uses new 4.5 Plus! features to check for mouse activity. *(PRODLOC.EEP) IF (ISTAT('MOUSEROW')) <> 4 THEN RETURN ENDIF IF (LASTKEY(0)) NOT IN ('[F2]','[MOUSEBUTTON1]') THEN RETURN ELSE CLS FROM 15 6 TO 23 78 BLACK CLS FROM 14 4 TO 22 76 RED WRITE ' Location Units Cost Extended Cost' + AT 15, 10 BLACK ON RED EDIT USING Prodloc WHERE model = .vmodel AT 15 ENDIF RETURN First the EEP checks to see if the mouse was last clicked on the form row the vloc variable is located on. We only want to call the windowed form if the mouse is actually clicked in this location. The LASTKEY function tests for either an F2 keystroke or mouse click. A single mouse click returns MOUSEBUTTON1, a double mouse click returns F2. The CLS commands creates a shadow box for display of the windowed form. The first CLS command clears a block of the screen from row 15, column 6 to row 23, column 78 using black as the screen color. The second CLS command overlays the black screen block with a red screen block. The black block becomes the shadow behind the red block. The WRITE command creates headings for the fields and the EDIT USING command displays the windowed form, prodloc, starting at row 15 with the locations for the particular model number. 4. Create the windowed form, prodloc. The form is created with fields located at the very top of the form definition screen. You must do this so the form displays at the correct screen position as specified in the AT portion of the EDIT USING command. It is important that the form have no literal text entered on it. It must have field locations only. The easiest way to place field labels and other text on the windowed form is with the WRITE command. Write the text to the screen at the appropriate locations before calling the form. Because the Form setting Clear screen before form use is set to No in this form, the text written to the screen will still display after the form is drawn. If your windowed form is a region like the Prodloc form, make sure you specify No to the question Do you want a border around the region?. The border around a region is stored as literal text. Set the background color of the form and the located fields to match the colors specified in the CLS command. All the colors can be set from the Form settings screen. 5. Edit data using the Product form. To see locations for a model, move to the located variable, vloc, that says 'Click for product locations' and press F2 or use the mouse. The windowed form displays the matching locations for the model. Using Esc exits the windowed form and returns to the Product form.