Question : Visual FoxPro 9 formset question

I have a VFP 9 application that utilizes a form set consisting of only two forms.  The main form (form1) loads data into a grid on the form based upon an SQL query from data entered into a text box either by the user or a barcode scanner.  The second form (form2) is hidden during the initial load of form1.

If the end user determines the data in the grid needs to be edited I have a command button that will make form2 visible and show form2. The second form queries and inventory master and displays the results of a cursor into a combo box. During testing of the application within VFP everything works perfectly.

However I now am ready to distribute the application via a setup program using InstallSheild.  During the init method of form1 I have the following command: application.visible = .f. to turn off the main Visual Fox Pro window.  I have the form1.showwindow property set to a top level form and form2.showwindow property set to: in top level form, I also have form2.alwaysontop property set to .T.  My problem is if I distribute the application and call form2 from form1 it is not visible...I do not get an error, I just can't see form2.  However if modify form1.init event and set application.visible = .t. when I call form2 it loads but it loads behind form1 into my task bar and I have to click on the task bar to bring the form to the forefront.

My goal is to obviously set application.visible = .f. and be able to load form2 into the top level form1.  What I am missing?  Any help would be greatly appreciated.

Answer : Visual FoxPro 9 formset question

If you use thisformset.addobject then you can leave the code in Form2 unchanged but you have to define separate class from it (means to remove Form2 from formset and save it as class).

If you need to access Form1 methods from "independent" Form2 then you cannot use the form name but you have to provide the form object reference of Form1 to Form2. You could find the Form1 object reference from _screen.forms or you can pass this reference as parameter:

If you will call Form2 from Form1 by
DO FORM Form2 WITH THISFORM
then the calling form reference is passed to Form2.Init method as a parameter and you may use this parameter value to access Form1 methods and properties. Remember the parameter is just variable having some scope - when the Init event code exits then this variable disappears so you have to store its value into some form property:

Form2.Init:
LPARAMETER loCallingForm
*-- Some Init code
*-- Store the calling object reference
THISFORM.CallingFormReference = loCallingForm  && CallingFormReference is property of Form2
*-- etc.
RETURN

When referencing Form1 use simple:
THISFORM.CallingFormReference.command7.setfocus( )
THISFORM.CallingFormReference.command7.click

This approach is valid but not so correct in OO environment. Form2 should not know about all Form1 controls and their properties. You should call just some public method from calling form and this method should do the work.

Same rules are valid if the form is in a formset. In such case you should call mehods from the formset only and formset should propagate such call to its child forms. The concept is "Object encapsulation" and you should communicate via some public interface only.

I know, programs must be delivered sometimes...
Random Solutions  
 
programming4us programming4us