×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Create method to a dynamically created object

Create method to a dynamically created object

Create method to a dynamically created object

(OP)
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"

  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  

I found this thread, it helped a little but still struggling
https://www.tek-tips.com/viewthread.cfm?qid=357375

Thanks

RE: Create method to a dynamically created object

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: set all rightclick method of all textboxes in a form
and thread184-1819758: Adding a Procedure to Multiple Objects

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

RE: Create method to a dynamically created object

(OP)
Thanks, those threads are helpful.

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

RE: Create method to a dynamically created object

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

RE: Create method to a dynamically created object

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

RE: Create method to a dynamically created object

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close