Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Andy Kramek
  Where is Andy Kramek?
 Westminster Circle, Akron
 Ohio - United States
 Andy Kramek
 To: Russell Hill
  Where is Russell Hill?
 Sydney
 Australia
 Russell Hill
 Tags
Subject: RE: Firing of events
Thread ID: 221887 Message ID: 221912 # Views: 40 # Ratings: 1
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Sunday, March 22, 2009 1:08:35 PM         
   


> Hi all,
>
> Is the firing of (and the order of) events which occurs when a given initial event is fired documented anywhere?
>
> Or is it simply a matter of putting Messagebox()s in all the events of an object and then seeing what happens?
>
> I have several Containers on a form, all of which with many TextBoxes.
>
> All of the TextBoxes use .ControlSource by way of a Cursor reference and are updated with ThisForm.Refresh().
>
> What prompts this thread is that I also need some conditional colour-coding of the TextBoxes, and I was wondering which events (of the TextBoxes) were fired when I issued ThisForm.Refresh().
>
> Any help would be appreciated.
>
> Cheers,
>
> Russell.

No events fire. ThisForm.Refresh() is a broadcast method that tells all object to call their individual Refresh() methods (sort of like using SetAll() for a method). The only issue is in which order the individual controls fire their Refresh() and that depends on the order in which they were added to the form.

For what its worth, the way I handle this is with couple of custom properties on my textbox class named "cObjMode" and "cObjExpr". The refresh of the control then has this code:

WITH THIS
  DO CASE
    CASE .cObjMode = 'O'  && Optional
      .BackColor = RGB( 255, 255, 255 )  && White
      .ForeColor = RGB( 0,0,0 )  && Black
      .MousePointer = 0  && default
      .TabStop = .T.
      .ReadOnly = .F.
    CASE .cObjMode = 'M'  && mandatory
      .BackColor = RGB( 255,255,0 )  && Yellow
      .ForeColor = RGB( 0,0,0 )  && Black
      .MousePointer = 0  && default
      .TabStop = .T.
      .ReadOnly = .F.
    CASE .cObjMode = 'S'  && system set
      .BackColor = RGB( 128,128,128 )  && Dark Grey
      .ForeColor = RGB( 255,255,255 )  && Black
      .MousePointer = 1  && arrow
    CASE .cObjMode = 'R'  && read only
      .BackColor = RGB(192,192,192)  && Grey
      .ForeColor = RGB( 0,0,0 )  && Black
      .MousePointer = 1  && arrow
      .TabStop = .F.
      .ReadOnly = .T.
   OTHERWISE && Default to Optional
      .BackColor = RGB( 255, 255, 255 )  && White
      .ForeColor = RGB( 0,0,0 )  && Black
      .MousePointer = 0  && default
      .TabStop = .T.
      .ReadOnly = .F.
  ENDCASE
ENDWITH


A recursive custom method on the base form class handles setting these properties for all controls like this:
LPARAMETERS toObject, tlNoRefresh
LOCAL loRef, lnCnt, loPage, loColumn, lcExpr, luLastMode

DO CASE
  CASE toObject.BaseClass = 'Pageframe'
    *** Validate each page
    FOR EACH loPage IN toObject.Pages
      IF loPage.PageOrder = toObject.ActivePage
        *** Loop through the objects on the pages
        FOR EACH loRef IN loPage.Controls
          *** Validate form objects that require validation
          Thisform.SetObjMode( loref )
        ENDFOR
        EXIT
      ENDIF
    ENDFOR

  CASE INLIST( toObject.BaseClass, 'Form', 'Container' ) 
    *** Loop through all the objects on the form or in the container
    FOR EACH loRef IN toObject.Controls
      *** Validate objects that require validation
      Thisform.SetObjMode( loref )
    ENDFOR

  OTHERWISE
    *** Evaluate the Mode Expression and refresh the control's cObjMode
    IF PEMSTATUS( toObject, 'cModeExpr', 5 ) 
      IF ! EMPTY( toObject.cModeExpr )
        lcExpr = toObject.cModeExpr
        luLastMode = toObject.cObjMode
        toObject.cObjMode = &lcExpr
        *** Only refresh if value has changed
        IF ! tlNoRefresh AND toObject.cObjMode # luLastMode
          toObject.Refresh()
        ENDIF
      ENDIF
    ENDIF
ENDCASE  

RETURN


The final piece is to add a method to the form class that wraps the normal Refresh() in a handler for the mode properties. This method is named RefreshForm() and when called with the optional parameter of .T. it forces the re-evaluation and reset of all cObjMode properties:
LPARAMETERS tlSetObjMode
WITH Thisform
  .LockScreen = .T.
  IF tlSetObjMode
    .SetObjMode( This )
  ENDIF	
  .Refresh()
  .LockScreen = .F.
ENDWITH	


Now suppose I want a textbox to the Mandatory in Add mode (Black on yellow) and Read-Only (Black on Grey) in Edit/View mode, all I need to do to change the behavior is put an IIF() expression into the cModeExpr property like this:
IIF( ThisForm.ViewMode = "A", "M", "O" )

and after changing the form's mode I would simply call:
ThisForm.RefreshForm( .T. )

to have all text/editboxes adjust themselves. (Incidentally my Command Buttons, Checkboxes and Options have the same properties but instead of appearance they Enable/Disable/Hide themselves)

Regards
Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA

COMPLETE THREAD

Firing of events Posted by Russell Hill @ 3/22/2009 9:25:46 AM
RE: Firing of events Posted by Stefan Wuebbe @ 3/22/2009 9:57:28 AM
RE: Firing of events Posted by Russell Hill @ 3/22/2009 12:58:19 PM
RE: Firing of events Posted by Andy Kramek @ 3/22/2009 1:08:35 PM
RE: Firing of events Posted by Russell Hill @ 3/22/2009 11:28:31 PM