Subject Re: AutoDropNot
From Mervyn Bick <invalid@invalid.invald>
Date Wed, 7 Nov 2018 09:46:20 +0200
Newsgroups dbase.getting-started
Attachment(s) cholla2c.wfm

On 2018-11-07 12:00 AM, Tom wrote:

> Try the attached. This is what I have been struggling to do. :)
> Fond memories of Marko. Good guys like you and him are hard to find.
> Monkey see, monkey do works well for me.


Looks good.  One small thing though.  There's a lot of repeated code
throughout.  Any time you find yourself using the same code more than
once it's a good idea to factor the code out into a separate function.

I've moved two blocks of code into the functions create_cholla and
sort_array.

If you are going to use this construct often the next thing is to create
a custom entryfield control where the associated combobox is created
"behind the scenes" and all you need to do in the form is supply the
array for the combobox.  (Nothing is impossible if you don't have to do
it yourself. :-) )

Mervyn.



*
** END HEADER -- do not remove this line
//
// Generated on 11/06/2018
//
parameter bModal
local f
f = new BickCholla2cForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class BickCholla2cForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      metric = 6        // Pixels
      colorNormal = "LightGrey"
      height = 352.0
      left = 840.0
      top = 0.0
      width = 280.0
      text = ""
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      onOpen = {;this.value = "Rose"}
      height = 22.0
      left = 89.0
      top = 48.0
      width = 100.0
      fontSize = 11.0
      value = "Entryfield1"
   endwith

   this.ENTRYFIELD2 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD2)
      onGotFocus = class::JUMPING_CHOLLA
      onOpen = {;this.value = "Tomato"}
      height = 22.0
      left = 89.0
      top = 115.0
      width = 100.0
      fontSize = 11.0
      value = "Entryfield2"
   endwith

   this.ENTRYFIELD3 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD3)
      onGotFocus = class::JUMPING_CHOLLA
      onOpen = {;this.value = "West"}
      height = 22.0
      left = 89.0
      top = 182.0
      width = 100.0
      fontSize = 11.0
      value = "Entryfield3"
   endwith

   this.ENTRYFIELD4 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD4)
      onGotFocus = class::JUMPING_CHOLLA
      onOpen = {;this.value = "Mow Lawn"}
      height = 22.0
      left = 89.0
      top = 249.0
      width = 100.0
      fontSize = 11.0
      value = "Entryfield4"
   endwith


        Function Form_onOpen
        * ----------------------------- *
            if type('LockWindowUpdate') # 'FP'
         extern cLogical LockWindowUpdate( cHandle ) User32
      endif
        return
        *

        Function Jumping_Cholla
        * ------------------------------- *
                // create CHOLLA list for each entryfield ...
                do case
                        case this.name = "ENTRYFIELD2"
                                if type("form.aList") = 'U'
                                        form.aList = new array()
                                        form.aList.add( "Peaches" )
                                        form.aList.add( "Banana" )
                                        form.aList.add( "Rhubarb" )
                                        form.aList.add( "Pumpkin" )
                                        form.aList.add( "Apple" )
                                        // purposly left off entryfield2.value of 'Tomato"
                                        *
               form.aList = class::sort_array(form.entryfield2.value,form.alist)
                                endif
                                *
            class::create_cholla(form.entryfield2,'form.alist')
                                *
                        case this.name = "ENTRYFIELD3"
                                // and repeat for new entryfield
                                *
                                // create CHOLLA list for each entryfield ...
                                if type("form.bList") = 'U'
                                        form.bList = new array()
                                        form.bList.add( "North" )
                                        form.bList.add( "South" )
                                        form.bList.add( "East" )
                                        form.bList.add( "West" )
                                        // purposly included entryfield3.value of 'West"
                                        *
               form.bList = class::sort_array(form.entryfield3.value,form.blist)
                                endif
                                *
            class::create_cholla(form.entryfield3,'form.blist')
                                *
                        case this.name = "ENTRYFIELD4"
                                if type("form.cList") = 'U'
                                        form.cList = new array()
                                        form.cList.add( "Rake Leaves" )
                                        form.cList.add( "Clean Gutters" )
                                        form.cList.add( "Wash Car" )
                                        form.cList.add( "Walk Dog" )
                                        form.cList.add( "Shovel Snow" )
                                        // purposly left off entryfield4.value of 'Mow Lawn"
                                        *
               form.cList = class::sort_array(form.entryfield4.value,form.clist)
                                endif
                                *
            class::create_cholla(form.entryfield4,'form.clist')
                                *
                endcase
                *
      form.oLastFocus = form.activeControl // where was I ?
      LockWindowUpdate(0)
      form.CHOLLA.setFocus()
      form.CHOLLA.keyboard("{F4}")
        return
        *
  
   function sort_array(oRefVal,aArray)
      local nRow
      if NOT EMPTY( oRefVal )
         nRow = aScan( aArray, oRefVal )
         if nRow = 0 // not already in list ...
            aArray.add( TRIM( oRefVal ) )
         endif
      endif
      *
      aSort( aArray ) // nice alphabetical list for user ...
      return aArray
   *  
      
   function create_cholla(oRef,cArray)
      // new OCHOLLA object
      LockWindowUpdate(form.hWND)
      form.CHOLLA = new COMBOBOX(form)
      with (form.CHOLLA)
         onLostFocus = class::Reset_Cholla
         systemTheme = false
         height = 24.0
         fontSize = 11.0
         style = 2        // DropDownList
         dropDownHeight = 132.0
      endwith  
      form.cholla.left = oRef.left
      form.cholla.top = oRef.top
      form.cholla.width = oRef.width+18
      form.cholla.dataSource = 'array '+cArray
      form.cholla.value = TRIM( oRef.value )
      return

        Function Reset_Cholla
        * --------------------------- *
                if TRIM( form.oLastFocus.value ) # form.CHOLLA.value // no use updating same value
                        form.oLastFocus.value = TRIM( form.CHOLLA.value ) // transfer value
                endif
                *
                release object form.CHOLLA
                *
                form.oLastFocus.before.setFocus()
                *
        return
        *

endclass

*
***
*