Wiki Home

How To Run Dynamic Code


Namespace: VB
How can I assign a code block to a form method, in run_time ? -- CCostaBR

You can with either Macro Substitution or EXECSCRIPT. What are you trying to do?

You can also (in VFP8+) use BINDEVENT to bind a form method to another method, though I don't know of any way of creating that other method dynamically. - ?wgcs

I tried creating a COM object which i could use in .NET to run VFP code on the fly in case of emergency. I didn't use the Macro Substitution method though. I tried writing my code to a prg then running the prg. This fails as the COM can't seem to find the prg. However, the EXECSCRIPT() method works fine!! A function i didn't even know existed :) Tim Hustler

You could try creating a class to wrap up a call to EXECSCRIPT(), like the following:
define class FunctionObject as Custom
   cMethod = []

   procedure INIT(pcParameters as String, pcMethod as String)
      this.cMethod = iif(vartype(pcParameters)="C","lparameters "+pcParameters+CR_LF,"") + pcMethod
   endproc

   function call(p01,p02,p03,p04,p05)
      local lcParamString as String
      lcParamString = left(",p01,p02,p03,p04,p05",4*(PCOUNT()))
      return execscript(this.cMethod &lcParamString)
   endfunc
enddefine


You would then create your codeblock:
loDistanceFunc = createobject("FunctionObject", "pnA,pnB", "return sqrt(pnA*pnA+pnB*pnB)")


And use BINDEVENT() to attach it to your form:
BindEvent(loForm, "method", loDistanceFunc, "call", 1)


--Tom

Category Questions Category Open Questions
( Topic last updated: 2004.11.17 05:52:37 AM )