Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programmatically creating method or event procedure
Message
From
23/02/1999 06:04:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00189903
Message ID:
00190347
Views:
19
>>>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
Oh well, I really don't know VFP runtime processing mechanisms involved, but in fact I use this in compiled exe and works. It was the case for FP 2.x too. Why not try once in an EXE (BTW I not only do it in an EXE but on a computer that has no VFP installation at all - except VFP runtime such as VFP500.dll which are needed to run for any VFP exe :)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform