Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variables in form
Message
De
04/12/2007 21:29:59
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01273093
Message ID:
01273197
Vues:
14
This message has been marked as a message which has helped to the initial question of the thread.
>If I declare a variable in init event of a form
>this variable is not found in a button or other object of the form
>
>I have to declare it as public
>
>Is it really necessary to declare the variable as public ?

Let me ellaborate on the reply Borislav gave.

A public variable, used to share data between form methods, has three different problems.

1. It may interfere - in both directions - with another variable declared anywhere else in your program, that happens to have the same name.

2. If you have two instances (copies) of the form open, the variable will also interfere. Please note that having two copies of the same form open is both useful and feasible.

3. If you forget to RELEASE the variable when the form closes, the variable will continue using memory. If you do RELEASE it, the shared variable for all copies of the form (see point 2) will be released.

All of these problems are solved beautifully with form properties (or class properties, in the case of classes).

In summary, using public variables just to share data among form methods is not convenient. However, a few public variables in the main program may be justified. It should be possible to have a single public variable, an "application object", to store different kinds of data for your application; all kinds of data can be stored in different properties of the application object. (An application object might store user name and user level, a list of open forms, or any other information which you need once for the entire application.)
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform