Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strange behavior
Message
From
11/03/1999 09:41:47
Mark Hall
Independent Developer & Voip Specialist
Keston, Kent, United Kingdom
 
 
To
11/03/1999 09:05:40
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00196313
Message ID:
00196331
Views:
28
>Hi...
>
>I have a form (F1) calling a program (P1) which in turn calls another form (F2).
>
>The behavior I have is that F2 closes after it`s init event and P1 continue it`s execution.
>
>Any ideas...

If your program P1 does something like

loForm2 = CREATEOBJECT("Form2")

When P1 closes, the variable loForm2 will be released automatically, and that is why Form2 disappears.

So, a quick fix would be to declare the variable loForm2 as PUBLIC, although this should be avoided as it leads to bad programming practices.

Another idea (if form2 is a 'child' of form1) might be to pass a reference of form1 through the program, and attach the new form as a contained object from form1

*-- Form1
DO Prog1 WITH THIS

*-- Prog1
PARAMETERS loForm
loForm.Addobject("SecondForm", "Form2")
loForm.SecondForm.Show()


The last, and probably best idea is to create a form manager class for your application. This object can then be called whenever a new form id required to be created.

*-- Startup Program
PUBLIC goFormManager
goFormManager = CREATEOBJECT("cusFormManager")

you would then create a CreateForm and DestroyForm method in the FormManager class. These methods could be called from anywhere in your application, whenever form management is required.

Whenever you create a form, the FormManager object shoudl attach a reference to it in an internal array e.g.

*-- Formmanager.CreateForm
PARAMETERS lcFormClass
LOCAL loForm

loForm = CreateObject( lcFormClass)
THIS.FormCount = THIS.FormCount + 1
DIMENSION THIS.FormList( THIS.FormCount)
THIS.FormList( THIS.FormCount) = loForm
RETURN loForm

*-- In your application, whenever you need to create a form :-
loNewForm = goFormManager.CreateForm("FormClassName")
loNewForm.Show()


Finally you would need to create a corresponding Destroy form method in your form manager, which would delete the element in the FormList array.

It sound complex but it's worth it in the long run as it makes the whole business of showing, hiding, managing formas and toolbars much easier. There might even be an example class definition in the libraries section of the UT (I haven't looked).

Whew, long answer, but it might have given you some ideas.
Regards
Mark

Microsoft VFP MCP
Menulib - OO Menus for VFP www.hidb.com/menulib
Previous
Reply
Map
View

Click here to load this message in the networking platform