crear botones de manera interactiva
Saludos a todos.
Mi problema es como puedo crear botones de una manera interactiva.
Hago una consulta y por cada resultado q me genera creo un boton. Lo q pasa es q no se q hacer para hacer referencia a despues a cada uno de esos botones.
Creo una variale en la q guardo el nombre del boton y luego utilizo esa variable para hacer referencia pero no me reconoce el boton
&&cont es un contador para cada boton
cBoton="cmdTemporal"+cont
thisform.additem(cBoton,'commandbutton')
thisform.cBoton.Caption=cBoton
Se supone q con ese codigo me tendria q crear el boton y darle a la propiedad Caption el nombre del boton pero no lo hace.
Alguien podria decirme q es lo q esta mal en el codigo? O como crear esos botones de forma interactiva.
Gracias por adelantado
BYEEEEEEEEEEEEEEEEEEEEEEEEEE
Mi problema es como puedo crear botones de una manera interactiva.
Hago una consulta y por cada resultado q me genera creo un boton. Lo q pasa es q no se q hacer para hacer referencia a despues a cada uno de esos botones.
Creo una variale en la q guardo el nombre del boton y luego utilizo esa variable para hacer referencia pero no me reconoce el boton
&&cont es un contador para cada boton
cBoton="cmdTemporal"+cont
thisform.additem(cBoton,'commandbutton')
thisform.cBoton.Caption=cBoton
Se supone q con ese codigo me tendria q crear el boton y darle a la propiedad Caption el nombre del boton pero no lo hace.
Alguien podria decirme q es lo q esta mal en el codigo? O como crear esos botones de forma interactiva.
Gracias por adelantado
BYEEEEEEEEEEEEEEEEEEEEEEEEEE
Que tal Chemon.
En vez de Additem, debes utilizar "AddObject" ya que lo que estas agregando a la forma es un objeto tipo botón, additem se utiliza por ejemplo para agregar columnas en modo de ejecución a un ComboBox.
Este es un muy buen ejemplo en la ayuda de VFP.
frmMyForm = Createobject(\'Form\') && Create a Form
frmMyForm.Closable = .F. && Disable the Control menu box
frmMyForm.AddObject(\'shpLine\',\'Line\') && Add a Line control to the form
frmMyForm.AddObject(\'cmdCmndBtn1\',\'cmdMyCmndBtn1\') && Up Cmnd button
frmMyForm.AddObject(\'cmdCmndBtn2\',\'cmdMyCmndBtn2\') && Down Cmnd button
frmMyForm.AddObject(\'cmdCmndBtn3\',\'cmdMyCmndBtn3\') && Quit Cmnd button
frmMyForm.shpLine.Visible = .T. && Make Line control visible
frmMyForm.shpLine.Top = 20 && Specify Line control row
frmMyForm.shpLine.Left = 125 && Specify Line control column
frmMyForm.cmdCmndBtn1.Visible =.T. && Up Command button visible
frmMyForm.cmdCmndBtn2.Visible =.T. && Down" Command button visible
frmMyForm.cmdCmndBtn3.Visible =.T. && Quit Command button visible
frmMyForm.Show && Display the form
Read Events && Start event processing
Define Class cmdMyCmndBtn1 As CommandButton && Create Command button
Caption = \'Slant \<Up\' && Caption on the Command button
Left = 50 && Command button column
Top = 100 && Command button row
Height = 25 && Command button height
Procedure Click
Thisform.shpLine.Visible = .F. && Hide the Line control
Thisform.shpLine.LineSlant =\'/\' && Slant up
Thisform.shpLine.Visible = .T. && Show the Line control
Enddefine
Define Class cmdMyCmndBtn2 As CommandButton && Create Command button
Caption = \'Slant \<Down\' && Caption on the Command button
Left = 200 && Command button column
Top = 100 && Command button row
Height = 25 && Command button height
Procedure Click
Thisform.shpLine.Visible = .F. && Hide the Line control
Thisform.shpLine.LineSlant =\'\\' && Slant down
Thisform.shpLine.Visible = .T. && Show the Line control
Enddefine
Define Class cmdMyCmndBtn3 As CommandButton && Create Command button
Caption = \'\<Quit\' && Caption on the Command button
Cancel = .T. && Default Cancel Command button (Esc)
Left = 125 && Command button column
Top = 150 && Command button row
Height = 25 && Command button height
Procedure Click
Clear Events && Stop event processing, close Form
Enddefine
Alex Vargas
En vez de Additem, debes utilizar "AddObject" ya que lo que estas agregando a la forma es un objeto tipo botón, additem se utiliza por ejemplo para agregar columnas en modo de ejecución a un ComboBox.
Este es un muy buen ejemplo en la ayuda de VFP.
frmMyForm = Createobject(\'Form\') && Create a Form
frmMyForm.Closable = .F. && Disable the Control menu box
frmMyForm.AddObject(\'shpLine\',\'Line\') && Add a Line control to the form
frmMyForm.AddObject(\'cmdCmndBtn1\',\'cmdMyCmndBtn1\') && Up Cmnd button
frmMyForm.AddObject(\'cmdCmndBtn2\',\'cmdMyCmndBtn2\') && Down Cmnd button
frmMyForm.AddObject(\'cmdCmndBtn3\',\'cmdMyCmndBtn3\') && Quit Cmnd button
frmMyForm.shpLine.Visible = .T. && Make Line control visible
frmMyForm.shpLine.Top = 20 && Specify Line control row
frmMyForm.shpLine.Left = 125 && Specify Line control column
frmMyForm.cmdCmndBtn1.Visible =.T. && Up Command button visible
frmMyForm.cmdCmndBtn2.Visible =.T. && Down" Command button visible
frmMyForm.cmdCmndBtn3.Visible =.T. && Quit Command button visible
frmMyForm.Show && Display the form
Read Events && Start event processing
Define Class cmdMyCmndBtn1 As CommandButton && Create Command button
Caption = \'Slant \<Up\' && Caption on the Command button
Left = 50 && Command button column
Top = 100 && Command button row
Height = 25 && Command button height
Procedure Click
Thisform.shpLine.Visible = .F. && Hide the Line control
Thisform.shpLine.LineSlant =\'/\' && Slant up
Thisform.shpLine.Visible = .T. && Show the Line control
Enddefine
Define Class cmdMyCmndBtn2 As CommandButton && Create Command button
Caption = \'Slant \<Down\' && Caption on the Command button
Left = 200 && Command button column
Top = 100 && Command button row
Height = 25 && Command button height
Procedure Click
Thisform.shpLine.Visible = .F. && Hide the Line control
Thisform.shpLine.LineSlant =\'\\' && Slant down
Thisform.shpLine.Visible = .T. && Show the Line control
Enddefine
Define Class cmdMyCmndBtn3 As CommandButton && Create Command button
Caption = \'\<Quit\' && Caption on the Command button
Cancel = .T. && Default Cancel Command button (Esc)
Left = 125 && Command button column
Top = 150 && Command button row
Height = 25 && Command button height
Procedure Click
Clear Events && Stop event processing, close Form
Enddefine
Alex Vargas