when developing, how many times have you had to issue a clear all in the command window only to find your objects and other settings also were cleared?

for me i use foxtabs, as well as some additional tools accessed by custom toolbars. all these are loaded at startup by my custom vfpstart.prg and issuing a clear all wipes all these utilities out and i have to run vfpstart again.

in fact, in the latest issue of foxrockx ric schummer, in his article on foxtabs has this to say:

the reason i made  the  request(for the -m option)  is executing clear all  in  the command window will wipe out  the  instance of foxtabs. i want something on the tools menu so i can quickly get my tabs back after testing a program or needing to reset the development environment.

now those of you who have never heard of burkhard stiller and have never visited his blog, are missing out on some very interesting and revealing ideas and posts. this blog post  is my implementation of an idea he posted here that i find excellent. i am talking about "unbreakable objects". since bukhard has done such an excellent job, i will not repeat what he has explained so well. just go to the link above, and read and digest all 3 parts of his post on unbreakable objects and this will give you a better insight into what i am going to show here.

ok. with all that cleared up and armed with your new knowledge of vfp's _shell let me show you what i have done to implement this idea in my ide.

as bukhard explained stuffing a vfp command into the system variable _shell causes vfp to execute that command immediately.

now i use a vfpstart.prg to load all my utilities into the vfp ide on startup and so should you. basically for those who do not know, you can get vfp to run any prg or app on startup by a setting as shown below.

now here is the partial contents of my vfpstart.prg

* both vfpstart & bbpersistvars prgs must be in the same directory, usually vfp

cprg = justpath(sys(16))+"\bbpersistvars.prg"

* create the variable

if vartype(_screen.omyvars) = "u"

    _screen.newobject("omyvars","bbvars",cprg)

endif

* fill the shell cmd

_shell = [do ]+ cprg +[ with 'do ]+sys(16)+[']

* add a menu item to tools

m.nbar = 0

for m.i = 1 to cntbar("_mtools")

    if prmbar("_mtools", getbar("_mtools", m.i)) == strtran ("\<persistvars", '\<', '')

        m.nbar = getbar("_mtools", m.i)

        exit

    endif

endfor

if m.nbar == 0

    m.nbar = cntbar("_mtools") + 1

endif

define bar m.nbar of _mtools after _mtl_references ;

prompt "\<persistvars" ;

message "persists your ide"

* set the mark on

set mark of bar m.nbar of _mtools to .t.

* save bar for later

_screen.omyvars.nbarnum = m.nbar

* function showpersistmenu is at the end

on selection bar m.nbar of _mtools do showpersistmenu

* below you can add all the other commands you normally have in vfp start

* i have left some of mine in as an example

do c:\vfp8\tools\versatools\versatls.app

define bar 6 of poputil prompt "messagebox wizard" ;

message 'a messagebox wizard'

on selection bar 6 of poputil do c:\vfp8\tools\msgbox\mboxwiz.app

define bar 15 of poputil prompt "intellisense" ;

message 'add to intellisense'

on selection bar 15 of poputil do c:\vfp8\is_customizer.prg

define bar 16 of poputil prompt "form runner" ;

message 'run/edit forms'

on selection bar 16 of poputil do form c:\vfp9\mytools\formrunner.scx

define bar 18 of poputil prompt "sql select" ;

message 'connect to local sql'

on selection bar 18 of poputil do form c:\vfp9\sqlselect

with _screen

if vartype(.omyvars)= "o"

with .omyvars

.addproperty("oquickformat")

.oquickformat = newobject('formatbuttons','c:\vfp9\formattoolbar')

.oquickformat.show

endwith

else

.addproperty("oquickformat")

.oquickformat = newobject('formatbuttons','c:\vfp9\formattoolbar')

.oquickformat.show

endif

endwith

do c:\vfp9\getobj.prg

set procedure to c:\vfp9\bbutility.prg additive

* add menu item to tools

do c:\vfp9\tools\foxtabs\foxtabs\foxtabs.app with "-m"

* actually run it

do c:\vfp9\tools\foxtabs\foxtabs\foxtabs.app

* this is run when the menu option is ticked/unticked

procedure showpersistmenu

lparameters tnbarnum

if vartype(_screen.omyvars) = "o"

_screen.omyvars.persistvars = not _screen.omyvars.persistvars

set mark of bar _screen.omyvars.nbarnum of _mtools to _screen.omyvars.persistvars

endif

endproc

now certainly your prg will differ. most are custom settings & utilities i load into my ide, but the items relevant to this post i will explain here:

 cprg = justpath(sys(16))+"\bbpersistvars.prg"

bbpersistvars is a custom class which i will explain about soon. this class must be stored in the same directory as vfpstart. the above line just establishes the full path & file name of my custom class.

next we create a new object in  _screen. it is this object and its properties we will make unbreakable to clear all

 if vartype(_screen.omyvars) = "u"

    _screen.newobject("omyvars","bbvars",cprg)

endif

bbvars is a class that is in the bbpersistvars.prg

* fill the shell cmd

_shell = [do ]+ cprg +[ with 'do ]+sys(16)+[']

this is the killer line of code. what we do is stuff _shell with this command (in my case)

_shell = "do c:\vfp9\bbpersistvars.prg with c:\vfp9\vfpstart.prg"

so what happens is that vfp will now try to run the command stuffed into its _shell and so bbpersistvars is run with a parameter of the vfpstart.prg - more later.

the rest of the code is bog standard vfpstart stuff, except here i save the menu item into my persistant object for later use:

_screen.omyvars.nbarnum = m.nbar

basically i add a menu item to tools so when unchecked, clear all wil not persist my object.

the final piece of vfpstart i want to explain is the function that gets run when the menu item is ticked/unticked:

the code is simple enough. basically i store the value of the ticked/unticked in my custom persistant object.

now here is the contents of my bbpersistvars.prg which i will explain inline.

 * this is called from the _shell statement

lparameters tcshellcmd

* if we have an object then set it up

if vartype(_screen.omyvars) = "o"

    _screen.omyvars.fillit(tcshellcmd)

endif

here i call the fillit function passing it the full path and filename of vfpstart

* this class is used in vfpstart - like this

    * if vartype(_screen.omyvars) = "u"

* _screen.newobject("omyvars","bbvars",cprg)

* endif

here the class is defined

define class bbvars as session

persistvars = .t.

nbarnum = 0

* a default value - changed later

cshellcmd = "do c:\vfp9\bbpersistvars"

hidden cshellcmd

hidden baseclass, class, classlibrary, comment, datasession, datasessionid, name, parent, parentclass, tag

hidden destroy, error, init, readexpression, readmethod ,resettodefault, writeexpression

function fillit

    lparameters tcshellcmd

    if vartype(tcshellcmd) = "c" and not empty(tcshellcmd)

        this.cshellcmd = tcshellcmd

    endif

endfunc

here again we have the killer method. when the class is destroyed by issuing a clearall we re-stuff vfpstart.prg into _shell which starts the cycle all over, thus persisting the apps & tools loaded into the ide.

function destroy

* reinsert instantiation

    if this.persistvars

        _shell = this.cshellcmd

    endif

endfunc

* just for fun

function mydocmd(ccmd2run as string) as boolean helpstring "runs the command passed"

    try

        &ccmd2run

    catch to oex

        ?oex.message

    endtry

endfunc

function error

endfunc

enddefine

and that is all that needs to be done. of course you can make this as complex or as simple as you want. you have an object that is "persisted" in vfp till you tell it not to. so using this you can store settings and also read them in from disk.

you can save your memory vars to disk in the destroy and load them into the object so they are available even if a clear all is issued.

you will find a copy of my vfpstart.prg and bbpersistvars.prg. you will need to adapt it to your own tastes.

once you get the basic idea about how powerful this technique is, then the juices will flow and more ideas of your own will come flowing.

so if you now issue a clear all, vfpstart will be loaded automatically and all your tools will be restored. you can even save and restore your memory variables if that is what you need.

enjoy.

unfortunately because of the amount of junk mail being generated from the weblog i have switched off comments. please post your comments, if any, at www.foxite.com

3 Responses to Don’t let VFP’s CLEAR ALL command scare you

Leave a Reply

Your email address will not be published. Required fields are marked *