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

Firing an Object's REFRESH event

Status
Not open for further replies.

prangster

MIS
Sep 14, 1999
18
0
0
US
Occassionally I desire to REFRESH one object to avoid the overhead of refreshing the entire form. For example: suppose I have a grid and a command button in a panel container object. I can fire the grid refresh event from the command button with a specific reference to the grid object: e.g. THIS.PARENT.grdPayables.REFRESH. However, if I move the command button (off the panel container onto the form container) the explicit reference changes: e.g. THIS.<panelname>.grdPayables.REFRESH. If I move the control I may have to change to code. Is there a way to make this more generic? Perhaps using the object's name, e.g. THIS.MYREFRESH( "grdPayables") to seek and fire only the specific object's event. Is there some way already built into FoxPro?
 
You can probably use
ThisForm.grdPayables.Refresh()
(You need to know the reference to the grdPayables for sure without which you cant refresh.)

GENERAL SUGGESTION: I always do the refresh in a different way rather than directly refreshing the screen..(in order to speed up the refreshing)

I have my very basic form class .. say.. 'mybaseform' with an added method 'refreshform'. All the forms are subclassed from this form and so inherits the method which is generic.

The code in the 'refreshform' is

************************************************************
** since the screen is locked and then refreshed.
************************************************************
LOCAL llResetLockScreen

llResetLockScreen = (This.LockScreen = .f.)
This.LockScreen = .t.

This.Refresh()

IF llResetLockScreen
This.LockScreen = .F.
ENDIF
************************************************************
This makes a screen locking and do the refreshing very fast.

The key is to call ThisForm.RefreshForm() whenever a refresh is needed instead of the individual refresh() or the forms refresh() which takes the overhead. Any specific processing to calculated fields etc. can still be keyed into the normal refresh() method, but the execution comes through the ThisForm.RefreshForm()

Hope this is helpful. :)
 
Tagging onto RAMANI's reply, I've found that sticking code into the REFRESH event of a form or container can be undesireable. I've seen cases where code that needed to be run once was run as many as six times because VFP kept calling the REFRESH. In cases where something very specific needs to happen during a screen refresh, I make a pseudo refresh method that does whatever my specific functionality might be and then calls the form's REFRESH.

For example, say I've got a form that has several controls that nominally work the same way, but need different labels depending on a property of the form... lets say I'm doing a form that needs to calculate something based on different currencies and the labels need to reflect a change in currency. To keep things simple lets say that I'm using currencies of $ (US) and Pounds Sterling, based on the value of a check box. The Click of the check box might call a form-level method: Curry_Refresh

FUNCTION Curry_Refresh

WITH THISFORM
IF .chkUSBucks.VALUE
.lblCmd1.CAPTION = "Cost/Framiss ($)"
.lblCmd2.CAPTION = "Cost/Dingle ($)"
....
.lblCmd5.CAPTION = "Cost/Doodad ($)"
ELSE
.lblCmd1.CAPTION = "Cost/Framiss (lbs)"
.lblCmd2.CAPTION = "Cost/Dingle (lbs)"
....
.lblCmd5.CAPTION = "Cost/Doodad (lbs)"
ENDIF

.REFRESH()
ENDWITH

ENDFUNCT

The idea is to perform this function only once and only when its needed.

Regards,
Thom C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top