Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
M. memory variable
Message
 
To
14/11/1998 10:48:04
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00157652
Message ID:
00157663
Views:
21
>Can anyone help me on a few problems using m. memory variable for scatter & gather command ?
>
>Problem
>=======
>
>1. where should i create the m. memory variable in a form ?

The only time m. variables are useful is when you are planning to use them for a GATHER MEMVER or INSERT INTO table FROM MEMVAR statement.

>2. should i create the m. memory variable as public or private ?

Actually, you should always use local variables unless you have a specific need for a private or public variable. You would use a private variable when you need to modify the value of the variable in a routine that is called from the methos that created the variable. Public variables should be used sparingly and only when diverse areas of your application will need to access the variable. For example, you might define m.cuserid as public in your main program and set it to the login userid.

>3. i have tried to create the m. memory variable as public in the
> load event and it work fine. The problem came when i run the same
> form the second instance. Any changes on the m. variable in the
> second instance will also reflect on the first instance. If i
> clear the memory on the second instance in the unload event, the
> first instance get an error saying variable not found.

You need to understand that public variables are global in scope. Once defined, public variables are visible to every part of your application. If you change the value in one form, this change will be seen in every other form, procedure, menu, etc. At times, this behaviour is desirable and necessary. The key with variables is to limit their scope as much as possible (use local vars whenever possible).

>4. i have tried to create the m. memory variable in the init event
> but some objects that reference to the m. variable does not
> recognise it.

If objects on your form need to reference a variable when they initialize, then you will need a public variable. Since the init method of the form fires after the init method of every object on the form, you will need to declare the variable somewhere else. The load event fires before any of your form's objects are created, so you could declare it there. However, there is an even better place to declare your public variables - the main program. When you declare all your public variables in your main program, you are recognizing the fact that these variables are global in scope. You also create a central repository for public variables. This is really handy for debugging and maintenance - you always know where your public variables.

>
>Can anyone teach me how to setup the m. memory variable in the appropriate way in a form?

HTH!

>
>Thank you in advance
>
>Alaster Leong

-Brien
Brien R. Givens

Brampwood Systems
Previous
Reply
Map
View

Click here to load this message in the networking platform