Subject canOpen firing twice for DMD's query object + unexpected =/==
From Gaetano <gaetanodd@hotmail.com>
Date Thu, 17 Sep 2020 11:07:06 +1000
Newsgroups dbase.getting-started



Hi all,

I am trying to use a variable SQL statements depending on the value of
an_app-level variable in a DMD's canOpen event.

The following code seems to do what I was aiming for, however, I
stumbled on some unexpected things along the way:


In the following code, if I change the "==" operator to "=" in the DO
CASE block, the first DO CASE clause evaluates to true (i.e. the code
sees _app.varSQL as being an empty string) and cSQL doesn't get updated
as I expected it to in the second CASE clause.

I believe that the clause should not evaluate to true because
_app.cVarSQL is set to "getMissDaysDetails" and doesn't have any
trailing/inbetween/leading spaces. Any idea why the single "=" is not
working in that context?

The second issue I found is that the message boxes I put in the code to
investigate the above issue fire twice while opening the DMD. They fire
once before the DMD window is even visible, and a second time while the
form is opening but before the query object and grid become visible.

Could someone enlighten me on the reason that causes the event to fire
twice in this code?

** END HEADER -- do not remove this line
//
// Generated on 17/09/2020
//

//the CDM file only sets the database object, adds a CC file and an
//addField function

class SO2devDATAMODULE of BASESO2DEVCDATAMODULE from "BaseSO2dev.cdm"
    with (this.SO2ADO1)
       left = 26.0
       top = 43.0
       width = 115.0
       height = 112.0
    endwith

    this.ENERGYDATA1 = new ADOQUERY(this)
    with (this.ENERGYDATA1)
       canOpen = class::ENERGYDATA1_CANOPEN
       left = 162.0
       top = 60.0
       width = 115.0
       height = 146.0
       database = form.so2ado1
       connected = true
       sql = "select * from energydata"
       active = true
    endwith

    this.rowset = this.energydata1.rowset

    function ENERGYDATA1_canOpen()
       //set app level SQL flag
        _app.cVarSQL="getMissDaysDetails"
        //msgbox("_appvar= "+len(_app.cVarSQL))
        
                
      do case
        case _app.cVarSQL==""
            //leave SQL unchanged                                
        case _app.cVarSQL= "getMissDaysDetails"                                
          cSQL='SELECT count(distinct cast(eTimestamp as date)) as Days '
          cSQL+= 'from energydata order by Days'
         this.sql=cSQL
        endcase
        msgbox("cSQL = "+cSQL)
       return true

endclass