Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass param to unbound form from prg

Status
Not open for further replies.

dweis

IS-IT--Management
Apr 17, 2001
48
US
Please help! I'm looking for a way to create a dynamic button bar. The code is old 2.6 calling a browse window or calling @...say, @...get screens. The code pushes do statements onto function keys. I need a way to create a button bar that will allow me to pass parameters to it from the prg. Example - proc history pushes do sort, do seek, do details, etc. Proc inbound pushes do sort, do add, do viewnotes. I'd like to have the buttons change as each proc changes - setup 10 buttons on a form, pass proc names as parameters to the form & update the command button labels based on the proc called. I've read most of the threads on parameters & tried several things including
in prg:
local prog1, prog2, prog3
prog1 = wpseek
prog2 = wpsort
prog3 = wpview

do form history with prog1, prog2, prog3

In the init event of the form:
parameters prog1, prog2, prog3
test = prog1
test2 = prog2
test3 = prog3

on click events
button1 button2 button3
do test do test2 do test3
return return return

I've also tried replacing do test with do prog1, etc & that didn't work either. Also replace the parameters statement in prg with Local & also public.
I'm definately a newbie to VFP, using version 7. Any help would be appreciated.
 
HI
YOur question is confusing. It doesnt convery much to help you back. Anyway..
1. YOu can create a container class having buttons to do your sort, seek, view etc. and have in their click events generic code.
2. In your forms you can drop this class and make them perform identical activities on the default table open.

Hope this helps you :) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Sorry for the confusion. We're running an old Foxpro for Dos app, it's been upgraded to 2.6a & now to visual. We're having problems with some validation routines & looking for a way to keep all the screens as they are (they are not stand alone screens, they are @...Say @...Get screens.)In our code, the function keys are assigned as below:
do push_okl with
"do wpseek";
"do wpsort";
"do viewit";
nullstr;
nullstr;
nullstr;
nullstr;
"do hicanc";
"do hiesc";
nullstr;
nullstr;
nullstr;
nullstr
Push_okl is just a bunch of onkey label commands. The programs called from push_okl are different for different menu items. The idea was to have 1 unbound form with 2 rows of command buttons, replace the push_okl statement with "do form FORMNAME with PARAMETERS" The parameters being the procs called from push_okl, in this case wpseek, wpsort, viewit, hicanc, hiesc. The form would load & the 1st button, 2nd button, 3rd button, 9th button & 10th button would be assigned the variables from the calling program, do wpseek, do wpsort, etc. Each time a push_okl is encountered, the push_okl would be replaced with a call to this form & pass the program names as variables & change the command button labels. This will allow us to replace the old valid clauses used in our code with a onclick event that validates the control & then executes the program. I hope that clears some of the confusion.
 
What you're trying to do is mixing FPD2.6 ways with VFP. It's not recommended, but I understand the likely reasons for wanting to (because of having so much code to convert, our Company has taken several years to convert to VFP, still maintaining alot of FPD ways of doing things).

What I believe you're looking for is to create a ToolBar class which knows how to add/remove buttons, and which is always on the screen as a toolbar. (The trouble, I've found, with regular forms is that they will not cooperate with a BROWSE; one or the other controls... you can "BROWSE NOWAIT" then "READ WITH browsewin,buttonwin" but this gets really ugly and is difficult to control)

Just define a class in your base code, instantiate it, and use it (try putting this code in a .PRG and running it):
*in your main procedure:
RELEASE oMyToolBar
PUBLIC oMyToolBar
oMyToolBar = CREATEOBJECT('MyTB')
*Now, anywhere in your code, say, in EdCities.PRG:
oMyToolbar.Clear
oMyToolbar.AddButton('New City','','DO EdCities WITH "Add"')
oMyToolbar.AddButton('Delete','','DO DeleteRec')
oMyToolbar.visible = .t.
READ EVENTS
*Just remember, the code executed, "DO DeleteRec", is not
* Executed from the context of the currently running .PRG,
* that is, DeleteRec must be either a .PRG, or in the
* SET PROCEDURE list, or in the top executing .PRG that
* contains the READ EVENTS

DEFINE CLASS MyTBButton AS CommandButton
DoAction = ''
PROCEDURE Click
if not empty(THIS.DoAction)
LOCAL lcCmd
lcCmd = THIS.DoAction
&lcCmd
endif
ENDPROC
ENDDEFINE
DEFINE CLASS MyTB AS ToolBar
PROCEDURE Init
THIS.Dock(0)
ENDPROC
PROCEDURE Clear
LOCAL loButton
FOR EACH loButton IN THIS.Controls
THIS.RemoveObject( loButton.Name )
loButton=''
ENDFOR
ENDPROC
PROCEDURE AddButton( pcCaption, pcGraphic, pcDoAction )
LOCAL lcName
THIS.Visible = .T.
lcName = 'cmdButton'+alltrim(str(THIS.ControlCount))
THIS.AddObject( lcName, 'MyTBButton')
WITH Eval('THIS.'+lcName)
.Caption = pcCaption
.Picture = pcGraphic
.DoAction = pcDoAction
.Visible = .T.
ENDWITH
ENDPROC
ENDDEFINE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top