Wiki Home

Active Form


Namespace: Wiki
The Active Form property contains an object reference to the active form in a Form Set or the _SCREEN object. Not available at Design Time; read-only at Run Time.
Active Form can be used to pass parameters to forms in their Load event. _Screen.ActiveForm remains unchanged during a new form launch until the new form's Activate event. This means you can use this form during the Load event to gather information to use in setting up the data environment (for example).

Form parameters are not available until the Form Init event. However, by that time all the form's controls have already initialized themselves making changes to the Control Source of each difficult. Using the _Screen.ActiveForm property in the Load event, you can branch depending on values of controls. For example, you have a combobox with a list of choices. Based on what the end-user chooses, you want to display different fields from separate tables in a grid. The Load of the new form would have something like the following:

IF (Type("_Screen.ActiveForm.Name") = "C");
      AND (Type("_Screen.ActiveForm.combo1.Name") = "C")
   WITH _Screen.ActiveForm.Combo1
      DO CASE
      CASE .Value = Something
         SELECT Table1.Field1, Table2.Field1;
            FROM Table1, Table2;
            WHERE some filter condition;
            INTO CURSOR Cursor1
      CASE .Value = Something else
         SELECT Table3.Field1, Table4.Field1;
            FROM Table3, Table4;
            WHERE some filter condition;
            INTO CURSOR Cursor1
      etc ...
      ENDCASE
   ENDWITH
ENDIF


The control whose Control Source was being created here would not know the difference. The Control Source would be Cursor1.Field1 or Cursor1.Field2.

--
But I don't see how this helps in passing a parameter to the form. In my case, I have a table name (a string) that I want to set to the form's .Tag field. However, I would like to do this through the program calling the form. So far, I have
>>>
do form myform.scx with "mytable"
<<<
And in myform.Init() I have
>>>
parameters cTableName

this.tag = cTableName
<<<
How can I use _screen.ActiveForm to pass that parameter?

Currently, using the Do Form statement above, I am receiving .F. in the parameter for both Init and Form. So the expected way doesn't work. My form's .Window Type property is set to modeless (0).
-- Jason Timms
See Also: Forms Collection, Screen Active Form
Sources: VFP Help
Contributors: Larry Miller Steven Black
Category VFP Language - Key Words Category Exam 70-155 Hot Topic
( Topic last updated: 2006.10.11 09:42:15 AM )