Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Add assign method programatically
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01194810
Message ID:
01194867
Views:
16
>>>>>>>>>>>Is it possible to add an assign method to a class at run-time? If yes, will a scatter command execute it?
>>>>>>>>>>>Thanks,
>>>>>>>>>>>Trevor
>>>>>>>>>>
>>>>>>>>>>Version of VFP?
>>>>>>>>>VFP 9 SP1
>>>>>>>>
>>>>>>>>You could BINDEVENT() to the property, but I don't see any reason not to have ASSIGN method in your class. Can you tell us more?
>>>>>>>I have written a class that does a generic data conversion from fox dbf's to an sql backend. The only thing they have in common is the field name.
>>>>>>
>>>>>>That is great, but why you don't want to have ASSIGN method in that class?
>>>>>I don't know the names of the fields until run-time
>>>>
>>>>OK, you don't know the names, but what you want to do in that ASSIGN?
>>>>You easily can have:
>>>>
>>>>this.Property = [Something]
>>>>
>>>>w.o having ASSIGN method.
>>>Yes I understand. There are lots of other ways to solve this problem I was just enquiring whether it was possible to add an assign method to a class at run-time.
>>
>>You can, uh, not exactly ADD a code, but if you BINDEVENT():
>>
>>BINDEVENT(this,[SomeProperty],this,[SomeMethod])
>>
>>the code in SomeMethod will be called every time SomeProperty chenges its value.
>True but I will still need to be able to create SomeMethod at run-time.
>I had hoped to be able to do something like
>AddMethod(fieldname+"_assign",cFileName) with the code for "cFilename" being code generated at run-time as well.
>I guess the fundamental question is "can I add a method at run-time?"



You could do something like this in your SomeMethod:
EXECSCRIPT(FILETOSTR([ProprtyNameHere.PRG]))
And create your script and name it as the property you bound.
I.e. if you bind a property named MyProperty save the script in MyProperty.PRG, then in SomeMethod:
**** SomeMethod code:

LOCAL laEventName[1]
AEVENTS(laEventName,0)
EXECSCRIPT(FILETOSTR(laEventName[1].Name+[.PRG]))
never tested though :-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform