0

I have a VFP form on which I create a commandbutton dynamically. How can I create a function that will respond to onclick event ? Thanks in advance .

  • This is a good Q&A but I would be interested to know the scenario that calls for it. I've been writing VFP apps since version 3.0 came out and I don't think I have ever needed to add a commandbutton to a VFP form at runtime. – Caltor Nov 07 '12 at 14:18

1 Answers1

3

The best way to do this is create a button class that has the code you need. Then, dynamically add your button based on that button class.

Tamar

Tamar E. Granor
  • 3,817
  • 1
  • 21
  • 29
  • I don't know of any other way of doing this in VFP, so I would be interested in seeing any other approaches. But this will work. – Swordblaster Oct 04 '12 at 22:23
  • 1
    You can use BindEvent() to bind the Click method to the code. But unless the code itself needs to be generated at runtime, a button class is a better choice. – Tamar E. Granor Oct 05 '12 at 13:55
  • Tamar , but how should I pass some parameters to the created object of my defined class ? For example I have the class "myDefinedClass" and I add an object so : `thisform.addobject("action","myDefinedClass")` . The problem is how to pass some paramaters to the newly created object. Thanks. – Liviu Solcovenco Oct 06 '12 at 08:17
  • You can pass parameters in the call to AddObject and they're sent along to the Init method of the object. If that's not what you mean, then explain to what you want to pass the parameters. – Tamar E. Granor Oct 06 '12 at 12:34
  • I created a class based on `COMMANDBUTTON` and I want to get the parameter from another place where I created an instance of these object. Should I write so `thisform.addobject("action","myDefinedClass") with param 1 , param2` ? And how can I destroy an object ? ` Release ` seems to be not a proper command . Thanks. – Liviu Solcovenco Oct 06 '12 at 19:45
  • 1
    thisform.addobject("action","myDefinedClass", param 1 , param2). As for releasing such an object, use the RemoveObject method. – Tamar E. Granor Oct 06 '12 at 23:25