Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Stefan Wuebbe
 To: Rakesh Kumar
  Where is Rakesh Kumar?
 Rakesh Kumar
Subject: RE: Form with Prg file
Thread ID: 373833 Message ID: 373859 # Views: 67 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Wednesday, March 27, 2013 10:56:19 PM         

> Dear Experts
> i define form with prg file and i want to run another form with prg file, but i'm failed, so, please help me for this coding a under :
> thanks advance

The issue that I think you want to describe is that the object reference that you get back from the CreateObject() or NewObject() functions needs to get stored in a "place" that stays in scope as long as you need it.

In VFP, an undeclared variable is getting out of scope as soon as the method or procedure or PRG where it had been created is over and out of the Call Stack.
So that your first variable, the undeclared "main form" reference, persists because the "main.PRG" of a Vfp project does not leave the call stack as long as the application is running.

But as far as I read your code, your secondary (form) object reference variables are also undeclared and being created in object.methods() or procedures. So that each of them would run out of scope immediately (except when the referenced form objects would be "modal").

So what you would typically do is to find a place(s) where you can store your reference(s) that do not get released only a few milliseconds later.
Details would depend on your particular requirements, like for example whether certain Forms can be started as a single or multiple instances, whether there are "parent" and "child" forms that belong together, etc.

In general, you would probably use single properties of something like the _screen object or a custom "Form Manager" for single-instance forms, and array or collection properties for the multi-instance forms, or perhaps even (additional) undeclared variables or even Public ones also being created in the "main.PRG" (similar to the one you already have).
In other scenarios, where one parent can have one or many "satellites", you could use parentForm.customProperties to store the satellite references

FWIW, many (but not all) Vfp programmers would find it easier to use the visual Form or Class designer for visual objects.
IOW, you do not necessarily need to use "Define Class" PRG syntax for creating classes, you can also use the visual class designer that would store its result in VCX libraries -
the reason that many forum examples and tutorials are using that particular syntax is that it's plain text that can be displayed and copied directly in the browser



Form with Prg file Posted by Rakesh Kumar @ 3/27/2013 5:06:31 PM
RE: Form with Prg file Posted by Koen Piller @ 3/27/2013 6:13:19 PM
RE: Form with Prg file Posted by Rakesh Kumar @ 3/29/2013 3:51:04 AM
RE: Form with Prg file Posted by Koen Piller @ 3/29/2013 9:11:43 AM
RE: Form with Prg file Posted by Stefan Wuebbe @ 3/27/2013 10:56:19 PM