Wiki Home

Vfe Auto Bar

Namespace: Wiki

Here is handy thing for VFE developers: a toolbar that adds a button for each form in your aforms classlib.

To make version 1.1: [08/04/99 03:02:09 PM GMT]
  1. Make a new toolbar class using the command
    create class iAutoBar of ilibs\iToolbar as iToolbar from ilibs\iToolbar 
  2. Put the code below in iAutoBar.init
  3. Set iapplication.cMainToolbar of iapp.vcx to iAutoBar.

Here is what you will have:

You will have a toolbar that scans aforms.vcx and adds a button for each form.

Run a VFE app that does not have a cMainToolBar set, and you see the toolbar loaded up with all of your forms. Running them from the button is the same as picking them from the View menu, but you don't need to rebuild the project or menu to get access to them.

If someone will give me a better way to get a referance to the buttons as they are added, that would be great. I don't think this is the "right way": loNewBtn = eval( "this." + lcBtnNam ).

Version 2.1 beta [07/30/99 06:20:09 PM GMT]

To make life even easier, add an iadmintoolbarbutton to iAutoBar that will generate forms for all of your Presentation Objects (PO). Now you can look at them without manually putting them on a form.
  1. Make a new form class that takes the name of a PO as a parameter
    1. create class iAutoPOForm of ilibs\iforms as ipresentobjform from ilibs\iforms
    2. Put the code below in the init method.
  2. Make a button that uses iAutoPOForm to show all of your POs
    1. modify class iAutoBar of ilibs\iToolBar
    2. Add an iadmintoolbarbutton button
    3. change its name to ipobuilder.
    4. Set its caption to POs
    5. Put the code below in the click method.

Run the VFE app, press the POs button, and if you have a lot of POs, stand back! If your forms all end up in a pile at the bottom of the screen, "Window, Cascade" positions them where you can see them.

Question: How can I get the forms to start at (0,0)?

Bug: something to do with PO's that use the default data session. If you have two that are based on the same cursor, if you close them in the same order you opened them, you get an error. i think.

I originally had the name of the form being passed to the iAdminToolBarButton.init method. It made everything very "clean", until I found out that when controls added to a container, the visible property of the control get set to .f. Things got "dirty" trying to contend with that, and I just realized that with 3 more lines in the init of the toolbar I could skip passing the form name as a parameter and all of the code in the iAdminToolBarButton.init

There may still be a use for it, so I left it here.

  • Put the code below in the iAdminToolBarButton.init of itoolbar.vcx.
    The admin button will set its cform property to the parameter passed (if one is passed, and if there is not already something set in cform.) It will then set the caption to the value in .cform if the caption is not set. This is a nice way for the admin button to work anyway.

    * iAutoBar.init
    * Makes a tool bar out of all the forms in libs\aforms.vcx
    local ;
     laFrms(1), ;
     lnCtr, ;
     lcFrmNam, ;
     lcBtnNam, ;
    if file(  "libs\aforms.vcx" )
    	aVcxClasses( laFrms, "libs\aforms.vcx" )
    	for lnCtr = 1 to alen( laFrms, 1 )
    		lcFrmNam = laFrms( lnCtr, 1 )
    		lcBtnNam = "btn" + lcFrmNam
    		this.AddObject( lcBtnNam, "iAdminToolBarButton" )
    		loNewBtn = eval( "this." + lcBtnNam )
    		loNewBtn.cform = lcFrmNam
    		loNewBtn.caption = lcFrmNam
    		loNewBtn.autosize = .t.
    		loNewBtn.visible = .t.
    return dodefault()
    * end of iAutoBar.init

    * iAutoPOForm.init
    * at runtime, puts the passed PO on a form.
    with thisform
    	* Instantiate the PO as a new object of the form
    	* There is code in the PO's init that references thisform, 
    	* so it had better be a part of a form from the beginning.
    	.AddObject( "oPresObj", tcPONam )
 = 0
    	.oPresObj.left = 0 
    	.height = .oPresObj.height
    	.width = .oPresObj.width
    	* Set the forms caption to the name of the PO
    	.caption = "PO: " + tcPONam
    	.oPresObj.visible = .t.
    	* Set the Form's current PO to the PO we just created
    	.setpresentobj( .oPresObj )
    return dodefault()
    * end of iAutoPOForm.init

    * iPOBuilder.Click
    * Creates a form for each PO class in libs\apresent.vcx
    local ;
     laPOs(1), ;
     lnCtr, ;
    aVcxClasses( laPOs, "libs\apresent.vcx" )
    for lnCtr = 1 to alen( laPOs, 1 )
    	lcPONam = laPOs( lnCtr, 1 )
    	this.oApplication.doForm( "iAutoPOForm", lcPONam )
    * end of iPObuilder.Click

    * iadmintoolbarbutton.init
    lParameters ;
    * The admin button will set its .cForm property to the parameter passed.
    * If the caption is not set, 
    * it will set the caption to the value in .cform (regardless how it got there). 
    with this
    	* if ASSERT is off, the parameter takes precedence.
    	assert empty( tcFrmNam ) or empty( .cForm ) ;
    	 message "Assert failed:  Either tcFrmNam or .cForm need to be empty."
    	* If a parameter was passed, put it in .cForm
    	* The runs the form in cForm.
    	if !empty( tcFrmNam )
    		this.cForm = tcFrmNam
    	* If a caption has not been set, 
    	* set it to the name of the form, 
    	*  or "(nothing)" if there is no form.
    	if empty( .caption )
    		if empty( .cform )
    			.caption = "(nothing)"
    			.caption = .cForm
    return dodefault()
    * end of iadmintoolbarbutton.init

    New code: looks at all of the vcx's in libs/, adds buttons for each class that has 'form' in it's name.
    * iAutoBar.init
    * Makes a tool bar out of all the forms in libs\aforms.vcx
    Local ;
    	lnVcxs, lnVcx, ;
    	lnCtr, ;
    	lcFrmNam, ;
    	lcBtnNam, ;
    Local array ;
    	laVcxs[1], ;
    lnVcxs = Adir( laVcxs, "libs\*.vcx" )
    For lnVcx = 1 To lnVcxs
    	Avcxclasses( laFrms, laVcxs[lnVcx,1] )
    	For lnCtr = 1 To Alen( laFrms, 1 )
    		lcFrmNam = laFrms( lnCtr, 1 )
    		If "form"$Lower( lcFrmNam )
    			lcBtnNam = "btn" + lcFrmNam
    			This.AddObject( lcBtnNam, "iAdminToolBarButton" )
    			loNewBtn = Eval( "this." + lcBtnNam )
    			loNewBtn.cform = lcFrmNam
    			loNewBtn.Caption = lcFrmNam
    			loNewBtn.AutoSize = .T.
    			loNewBtn.Visible = .T.
    Return DoDefault()
    * end of iAutoBar.init

    Contributors Carl Karsten
    Category Visual FoxExpress Category Visual FoxExpress Tips And Tricks
  • ( Topic last updated: 1999.07.30 05:44:54 PM )