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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding code to _screen Methods 1

Status
Not open for further replies.

MossNelson

Programmer
Oct 30, 2003
26
US
I know that I can place an object such as a Command Button on the VFP desktop. For example,

_screen.AddObject("mycmd", "Commandbutton")
_screen.mycmd.width = 75
_screen.mycmd.height = 50
_screen.mycmd.caption = "Click Me"
_screen.mycmd.visible = .t.

How can I add my own code to the Click() method so that it executes along with the default behavior ?

-Nelson
 
It depends what version of VFP you use.
In VFP8 and 9 you could use BINDEVENT() for this.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
I am using VFP 9.

Given the sample code above, how could I use BINDEVENT so that for example a WAIT WINDOW "Hello" appears when the Command Button is clicked ?
 
Nelson,

Another option would be to create a custom command button class. Add the required code to the Click of the class.

Then proceed as before, but instead of using the native command button, use your own class:

_screen.AddObject("mycmd", "MyCmdClass")

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Code:
_screen.AddObject("mycmd", "Commandbutton")
_screen.mycmd.width  = 75
_screen.mycmd.height = 50
_screen.mycmd.caption = "Click Me"
_screen.mycmd.visible = .t.
_screen.AddObject([oMyEvents],[oMyEvents])
BINDEVENT(_screen.MyCmd,[Click],_screen.oMyEvents,[ClickMe],1)
READ EVENTS

DEFINE CLASS oMyEvents AS Custom
       PROCEDURE ClickMe
              WAIT WINDOW [Hello]
              CLEAR EVENTS 
       ENDPROC
ENDDEFINE
[/code]

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks for 2 good suggestions and this works nicely.

Can you explain the need for the READ EVENTS ?

I'm wondering about that since the CLICK() code performs a CLEAR EVENTS yet the button still keeps on working.

-Nelson

 
It works because I didn't put any cleaning code after READ EVENTS :)

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Nelson,

The READ EVENTS is only needed if there is some further code to be executed after you have created the button. If you just want to use Borislav's code as a sample to add to an application, you should omit the READ EVENTS and CLEAR EVENTS shown in the code.

To get rid of the button, you should execute:

_screen.RemoveObject("mycmd")

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

In one of my apps I would like to allow users to drag and create shortcuts to customers similar to how icons appear on the windows desktop.

I am using command buttons with the icon pic for "Customer" in my application and the caption of the customer code.

Clicking on one of these goes direct to the editing screen and opens that customer.

At user login I am reloading the shortcut set for each user.

True, I could have used my own form as the top level form but I wanted to try it this way.

-Nelson







 
Nelson,

Sounds like an interesting idea.

In my own app, I have a "Favourites" menu, a bit like in Internet Explorer. When users are looking at a particular customer, supplier or whatever, they can click an Add to Favourites button on the form. That causes the customer to appear on the Favourites menu. There is a Favourites table that drives the process, with each user having their own entries.

It seems to be quite a popular feature. But if I had thought of your idea of dragging the customer to the background screen, I might have done it that way instead.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top