Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Programmatically creating method or event procedure
Message
De
22/02/1999 06:49:32
 
 
À
22/02/1999 06:16:44
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00189903
Message ID:
00189907
Vues:
12
>>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.

This works, but only if you're using the development version of VFP to run ypour code - you can't do this directly from a compiled .EXE, since there's no built-in mechanism to convert the text to a compiled form.

One 'trick' here is to use CodeBlock(), which provides an interpreter that can be included in the compiled application and used to execute the code built on the fly.

>
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.
>
>* edtCode.value at the point you call above method
>define class mytxtbox as textbox
>  procedure someprocedure
>    * Some code
>  endproc
>enddefine
Cetin
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform