Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Form going out of scope
Message
De
28/07/2006 10:26:45
 
 
À
27/07/2006 14:54:05
Dennis Schuette
Customized Business Services, Llc
Yuma, Arizona, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01140798
Message ID:
01141098
Vues:
18
>>>I have two non modal forms that I want to share data and interact.
>>>
>>>Form1.command1.Click()
>>>if TYPE("Form2") == 'O' AND NOT ISNULL(Form2)
>>> Form2.Show()
>>>else
>>> do form2
>>>endif
>>
>>>This works correctly. If Form2 has been previously opened, the .Show() method works as expected. If Form2 has not >been opened, it runs correctly.
>>
>>>In Form2.command2.Click() I have the following code:
>>
>>vif TYPE("Form1") == 'O' AND NOT ISNULL(Form1)
>>> Form1.Show()
>>>else
>>> do form1
>>>endif
>>
>>>The reference to Form1 is no longer in scope. I get an 'object Form1 is not found' error.
>>
>>You need to set a reference point for both forms, I would suggest adding a custom property to the _SCREEN variable:
>>
>>
>
>>IF NOT PEMSTATUS(_screen,"MyRef",5)
>> ADDPROPERTY(_SCREEN,"MyRef[1]",.F.)
>> DIMENSION _SCREEN.MyRef[2]
>> _SCREEN.MyRef[1] = .NULL. && Reference to form 1
>> _SCREEN.MyRef[2] = .NULL. && Reference to form 2
>>ENDIF
>>DO FORM Form1
>>
>
>>
>>Then in the Init and Destroy methods of Form1:
>>
>>
>
>>PROCEDURE Init
>>_SCREEN.MyRef[1] = thisform
>>ENDPROC
>>
>>
>>PROCEDURE Destroy
>>_SCREEN.MyRef[1] = .NULL.
>>ENDPROC
>>
>
>>
>>The same in the Init and Destroy methods of Form2:
>>
>>
>
>>PROCEDURE Init
>>_SCREEN.MyRef[2] = thisform
>>ENDPROC
>>
>>PROCEDURE Destroy
>>_SCREEN.MyRef[2] = .NULL.
>>ENDPROC
>>
>>
>>
>>Now either form can access the other via the _SCREEN.MyRef reference. Use the ISNULL() function to determine if the form is opened. If there can be multiple open windows, then you will need a more extensive collection to manage the form references.
>
>Greg, thanks for the detailed code. One more question:
>
>When I determine that Form1 exists,
>isnull( _SCREEN.MyRef[1] ) = .F.
>how do I reference the form and execute the .Show method?

You can reference either form's methods or properties or controls like this from Form2 to access Form1 (also assume that form1 has a commandbutton named cmdOpen):
IF .NOT. ISNULL(_SCREEN.MyRef[1])
  IF .NOT. _SCREEN.MyRef[1].Visible
    _SCREEN.MyRef[1].Show()
  ENDIF
  _SCREEN.MyRef[1].cmdOpen.Click()
  ...
ENDIF
BTW -- any other form can also access this reference (_SCREEN.MyRef[1]).
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform