Yes, that is a simpler solution. However, you have to hard code the
commands that each click event trigger, in your example, 9, with a do
case construct
I used your earlier solution (bindevent) and came up with a general
approach:
** form LOAD event
set procedure to button_maker.prg additive
** form INIT event
Local cCaps,cComs
cCaps =[First,Second,Third,Fourth,Exit]
cComs=[MessageBox('First'),MessageBox('Second'),MessageBox('Third'),MessageBox('Fourth'),release
thisform]
this.AddObject ('grp','buttonmaker',5,cCaps,20,200,cComs)
this.grp.visible = .t.
and I simply call the form thus:
do form myform
in this manner, I use two form properties, one for the captions I want
in each button and another one for the code that should be triggered by
the click event of each button.
the class receives those two properties as parameters, as well as the
number of buttons and the position of the commandgroup in the form
the class uses getwordnum in a for-next loop to place the captions on
the buttons and another loop with getwordnum to place the code to be
triggered in the click event of each button, using bindevents as you
proposed.
It works like a charm
Rafael Copquin
DEFINE CLASS BUTTONMAKER AS COMMANDGROUP
cCommand = ''
cCaptions = ''
PROCEDURE INIT
Lparameters pnButtQy,pcCaptions,pnTop,pnLeft,pcCommands
Local nButtHt,nButtWt,nFirstTop,nSeparator,nWtIncrease
this.cCommand = pcCommands && COMMANDS TO PLACE IN CLICK EVENT OF BUTTONS
this.cCaptions = pcCaptions && BUTTON CAPTIONS DERIVED FROM A STRING
SENT AS PARAMETER
nButtHt = 36 && BUTTON HEIGHT
nButtWt = 168 && BUTTON WIDTH
nFirstTop = 5 && FIRST BUTTON TOP
nSeparator = 2 && BUTTON SEPARATOR
nWtIncrease = 5 && COMMAND GROUP WIDTH INCREASE IN RESPECT
OF CONTAINED BUTTONS'S WIDTH
WITH THIS
.top = pnTop
.left = pnLeft
.width = nButtWt + nWtIncrease
.backstyle = 0 && transparent
.borderstyle = 0 && none
.buttoncount = pnButtQy
For i = 1 to .buttoncount
.buttons(i).height = nButtHt
.buttons(i).width = nButtWt
.buttons(i).caption = GetWordNum(this.cCaptions,i,[,])
.buttons(i).name = 'command'+Alltrim(Str(i))
BindEvent( .Buttons(i), 'Click', this , 'btnClick' )
EndFor
.buttons(1).top = nFirstTop
For i = 2 to .buttoncount
.buttons(i).top = .buttons(i-1).top + nButtHt + nSeparator
EndFor
.height = (pnButtQy * nButtHt)+ (nSeparator * pnButtQy) +
.buttons(1).top
ENDWITH
ENDPROC
PROCEDURE btnClick
Local cComm,oButton,K
AEvents(aCallingEvent,0)
oButton = aCallingEvent(1)
if vartype(aCallingEvent) <> "U"
For K = 1 to this.ButtonCount
If this.Buttons(K) = oButton
cComm = GetWordNum(this.cCommand,K,[,])
&cComm
endif
endfor
endif
ENDPROC
ENDDEFINE
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.