Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create method to a dynamically created object

Status
Not open for further replies.

sstek-tips

Programmer
Feb 14, 2023
2
GB
Hello,

This is my first post to tektips. I now have about a couple of weeks experience of foxpro and hitting blocker at every turn, but enjoying getting round them.
I am using foxpro V9.

Is there a way to create an event method, eg a click method for an object created dynamically?

I have a form with 3 dynamically created sliders and they realise on the screen quite nicely.
thisform.AddObject(_sliderName, "olecontrol", "MSComCtl2.FlatScrollBar.2")

I now need to create a click method for each of these sliders. I can get the correct object reference but the
writeMethod() gives me a runtime error "Feature is only available if the object is in design mode"

[pre]
[tt] thisform.AddObject(_sliderName, "olecontrol", "MSComCtl2.FlatScrollBar.2")
* Find the form and the correct control within
FOR _formNo = 1 TO _screen.FormCount
IF _screen.forms[_formNo].name = thisform.Name
FOR _ControlNo = 1 to _screen.forms[_formNo].controlcount
IF(_screen.forms[_formNo].controls[_ControlNo].name = _sliderName)
MESSAGEBOX("we have the conrol for " + _sliderName)
_screen.forms[_formNo].controls[_ControlNo].writeMethod("click", "lnOne = this.value")
ENDIF
ENDFOR
ENDIF
ENDFOR[/tt] [/pre]

I found this thread, it helped a little but still struggling

Thanks
 
You're the third one asking within a short period of time. in short, no. Even though there is the WriteMethod method, it's not meant for objects at runtime, it is a method you can use on objects that are in "design mode", created in a designer (form/class designer) to edit them, i.e. to program them.

Also see thread184-1820504
and thread184-1819758

I mean, you have code, that includes code in a string:
Code:
lnOne = this.value
Write this into the click method of a class you want to have that click code and use that class.

Chriss
 
Thanks, those threads are helpful.

I created a wrapper class with event methods and I get the behaviour I want.
 
I wonder why a wrapper?

If you want to subclass an Olecontrol, that's also possible. The VFP Olecontrol class is for that. It's not possible to design ActiveX controls with it, it always hosts an OLE control. Maybe that's why you talk of a wrapper? Indeed that's quite right. If you put this on a form or if you create a class based on Olecontrol, the first dialog that will appear is "Insert Object" with a list of OLE controls VFP detects on the system and you pick one of them. You then have a mix of the Ole properties, events, and methods and some more VFP base events and properties.

It is a wrapper, because the actual Ole object is This.Object in such an Olecontrol based VFP class. But the class itself also is the OLE object and inherits all the Ole events and methods and properties the Olecontrol base class itself does not provide. So actually the OLE control integrates seamless into this. Well, in some cases, the context menu of the control will have an extra item for getting to OLE properties. For example, the MS treeview control (6.0) has a TreeCtrl item. There you can set properties that don't appear in the usual property list of the properties window.

From that level onwards you can also subclass your Olecontrol based VFP class and inherit the code and the OLE object, etc. So even an inheritance chain is possible.




Chriss
 
And, by the way, if you put an Olecontrol on a VFP form, the "Insert Object" dialog means you pick an OLE control to actually put on the form. Like ptting any VFP control onto the form, this means you have an instance of the control and in the Form designer you can write code into the instance events and method, too. That's not OOP, but you always have this last level of the instance object to write code into it.

It's often what non-OOP affine VFP developers only use to write their code, all code, of the form and its objects. That's why you see those threads I referred to. The other reason besides this little convenience that can become a pita once you realize you want to reuse this is, that then all code of all controls and the form is in one place. VFP otherwise always hides away the inherited code and doees not have all tools available as VisualStudio in that respec - F2 "Go to definition", to name just one hotkey Visual Studio has. At least VFP9 has the "View parent code" button in the code editor, when you edit class code, that shows the inherited code of the method or event you edit, but not the whole parent class.



Chriss
 
Hello,
Hi,just a quick idea , not on my PC :
What about a combination of bindevent() and execscript().
Not sure about bindevent on OLE-control

regards
tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top