>How to programmatically create method or event procedure of added object?
>I have form. In init event of this form I want add object and set up properties ,metods and events of this object.
>For example, next few lines create command button and set up caption and cancel properties.
>
>THISFORM.ADDOBJECT("cmdCancelBtn",'commandbutton")
>WITH THISFORM.cmdCancelBtn
> .CAPTION="quit"
> .CANCEL=.T.
>ENDWITH
>
>But how can I write, for example, procedure for CLICK event?
>
>Thanks
>
>Maros Klempa
Maros,
You can't do it and you can do it. You can do if it's OK to do on the fly tricks. Event, method code writing needs design time, and also creation time is considered as desing time. You may choose different tricks (not sure it's a trick). One that I find easy :
- Write your class programmatically to a temp file.
- Set procedure to that file.
- Add your object from that file library
ie: Assume you have a form with an edtCode object.
set textmerge on
set textmerge to myfile.prg
\<<thisform.edtCode.value>>
set textmerge to
set textmerge off
set procedure to myfile.prg
thisform.addobject("mytest","mytxtbox")
thisform.mytest.visible = .t.
define class mytxtbox as textbox
procedure someprocedure
endproc
enddefine
Cetin