Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing variables from forms to forms
Message
 
 
À
03/07/2000 23:37:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00387943
Message ID:
00388040
Vues:
10
>I need a variable passed from one form to another without using public variable, but needs to be used in the targets forms load event. How would I do that?
>
> THnaks Kelly

Passed variables are not available until the Init of a form. If you need variables available in the load event of called form, you can do it in a couple of ways.

1. Create a variable holder in the calling form. In the Load event of the called form. access that variable using _Screen.ActiveForm and store it to a property in the new form. Now you have access to it in the Load event of the form and the Init of all the contained controls.

The ActiveForm property of _Screen does not change from the old form to the new form until the Activate event fires of the new form. One gotcha to this technique occurs when forms that contain an ActiveX control are the calling form. Sometimes the ActiveX control itself is reported as the ActiveForm and not the containing form. You can easily get around this by checking _Screen.ActiveForm.BaseClass to see if it is "Form". If not, check its .Parent to see if that is a form and if so, use that when accessing your variable holder.
Load event
if type("_Screen.ActiveForm.BaseClass") = "C" ;
   and upper(_Screen.ActiveForm.BaseClass) = "FORM" then
   THIS.MyProperty = _Screen.ActiveForm.MyHoldervariable
else
   if type("_Screen.ActiveForm.Parent") = "O" ;
      and type("_Screen.ActiveForm.Parent.BaseClass") = "C" ;
      and upper(_Screen.ActiveForm.Parent.BaseClass) = "FORM" then
         THIS.MyProperty = _Screen.ActiveForm.Parent.MyHoldervariable
   else
      * ActiveX control is contained with X number of container layers
      * you have to parse up the chain to find the Form container
   endif
endif
2. Same idea as 1. but create the variable holder in an object that has global scope (not necessarily a global variable). Perhaps an application or form manager object created in your main program. You still need to store the variable to a property on your new form.

HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform