Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: George Kelly
  Where is George Kelly?
 Dromore
 United Kingdom
 George Kelly
 To: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 Tags
Subject: RE: maximizing my applications main screen
Thread ID: 110937 Message ID: 115407 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Thursday, December 07, 2006 4:51:26 PM         
   


> > > Ive declared a public variable m.addtofont in my Menu SETUP code.
> > >
> > > I can tell you that, as a consultant, if I am asked to work on someone elses code, I raise my rate for each PUBLIC devclarartion that I find < s >.
> > >
> > > There are better ways to do things than by using public variables.
> > >
> > > If you need something that is available for the life of your app, you can declare it as PRIVATE very early in your main startup program and it will be available until you quit the app.
> > >
> > >
> > > Regards,
> > > Marcia G. Akins
> > > Tightline Computers, Inc.

> >
> > Why do you disapprove of the use of PUBLIC variables in such an application, Marcia?
> >
> > George
>
> George,
>
> Public variables are visible EVERYWHERE. This means that they are visible anywhere in your app, but they are also changeable anywhere in your app. In VFP, it is quite acceptable for you to do the following.
>
>
> PUBLIC MyPublicVar
> MyPublicVar = 0
> MyPublicVar = [This is Text]
> MyPublicVar = .f.
> MyPublicVar = NULL
> RELEASE MyPublicVar
> 

>
> In fact, you could copy this code directly into the command window and run it and you would not get an error. Because public variables are visible anywhere in the app, after the PUBLIC declartion, each of these lines of code could run from anywhere in the app. While each of these lines of code would run without error, another line of code may not.
>
> Lets say that you declare m.addtofont PUBLIC in your Main.Prg and then in one of your forms, your code issues a
>
>
> m.addtofont = .F.
> 

> and then the user closes the form. This will run without error. Now, your user attempts to open another form and your code tries to do addition using m.AddToFont. That WILL give you an error - and it will be an error that is VERY difficult to find. (You can be pretty sure that your user will not remember which form was opened previously.)
>
> Like Marcia, I too HATE public variables. There are times that you need to use them, but I tend to avoid public variables where ever possible.
>
> You might want to consider storing this value in a table located in your users c:\Documents and Settings\UserName\Application Data\MyApp directory. This is probably something that your user would want to retain from one session to the next. If you save it to a table, you can open the table with the form, and you would be able to see it anywhere in that form, but it would not be a public variable. You would not be permitted to
>
>
> REPLACE MyTable.nAddToFont WITH .F.
> 

>
> Hope this helps.
>
> Ken
> You shall know the truth - and the truth shall set you free. (John 8:33)

I'm quite surprised to read this Ken.

I have to say I find public variables extremely useful, and I use them extensively.
I have done so since I began using very early versions of Foxpro.

My VFP7 apps are made up of a Menu (a compiled executable), and a number of programs, selected friom the menu, and all executables.
I declare a number of Public variables in the Menu SETUP code.
Values for these public variables are stored in a preferences table.

Some can be changed by the user in a Preferences program, as is the case in the example in this discussion.
The values are presented in a form in the preferences program. Changes are saved to the preferences table.

Normally, thats the only place where those variables can be changed and they are stored in a table, so available in every session.

m.addtofont is a numeric value (not a logical), used to adjust the point size in a derivative of Marcias code.
In my adaptation of Marcias code, Ive defined a function (which uses the m.addtofont variable) in a .prg file. That .prg is common, and compiled into each of the .exe's making up the app.
Each form in each executable (which reqires resizing) has a small code block in the init method, and calls the function to resize the objects.

m.addtofont remains visible to all the .exe programs selected from the menu - no errors.

I also have "belt and braces" code.
Since my program updates can be downloaded in isolation, I do a test using
vartype() function something like e.g.:
if vartype('m.addtofont')= 'U'
*Dont do anything
else
*Execute code for resizing
endif

I'm the sole developer of this stuff. Any variables in the Preferences table are "reserved" and are not redefined anywhere in ANY of the .exe's.

Its an alternative way of working, but it does work, and very effectively.

George

ENTIRE THREAD

maximizing my applications main screen Posted by Jahangir Khan @ 10/24/2006 10:41:17 AM
RE: maximizing my applications main screen Posted by Kiran Kumar Singh @ 10/24/2006 10:57:45 AM
RE: maximizing my applications main screen Posted by Saeed Afshari @ 10/24/2006 10:58:31 AM
RE: maximizing my applications main screen Posted by Borislav Borissov @ 10/24/2006 10:58:32 AM
RE: maximizing my applications main screen Posted by Dave Crozier @ 10/24/2006 10:59:29 AM
RE: maximizing my applications main screen Posted by Marcia Akins @ 10/24/2006 12:19:34 PM
RE: maximizing my applications main screen Posted by George Kelly @ 11/15/2006 10:53:09 AM
RE: maximizing my applications main screen Posted by Marcia Akins @ 12/6/2006 11:55:15 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 10:52:23 AM
RE: maximizing my applications main screen Posted by Marcia Akins @ 12/7/2006 12:40:34 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 1:08:03 PM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 1:44:55 PM
RE: maximizing my applications main screen Posted by tushar @ 12/7/2006 3:26:59 PM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 3:31:52 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 4:51:26 PM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 6:07:40 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 9:23:25 PM
RE: maximizing my applications main screen Posted by Don Higgins @ 12/7/2006 11:20:46 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/8/2006 11:21:35 AM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 3:29:56 PM
RE: maximizing my applications main screen Posted by Don Higgins @ 12/7/2006 11:22:33 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/6/2006 1:14:45 PM
RE: maximizing my applications main screen Posted by Barbara Peisch @ 10/24/2006 10:16:51 PM
RE: maximizing my applications main screen Posted by Mike Gagnon @ 10/25/2006 11:43:05 AM