Subject Re: FIELD DISPLAY
From Mustansir Ghor <mustan31@hotmail.com>
Date Fri, 14 Jul 2017 15:20:02 -0400
Newsgroups dbase.getting-started

Dear Bruce

Where is the procedure
set proc to tempsex.wfm

May be a result of this following class were also indicated as not found
class::SEX_CANCHANGE
class::SEX_BEFOREGETVALUE

Can you please guide as I was unable to run the program

Best Regards
Mustansir

Bruce Beacham Wrote:

> On 13/07/2017 09:17, Mustansir Ghor wrote:
> > I have a logical field SEX which is displaying as entryfield shown below
>
> > How can I modify this to display MALE or FEMALE
>
> The code below uses beforegetvalue and canChange on a calculated field
> to achieve this.
>
> Note that the calculated field is set up in the overriding
> open/readmodal handlers.    This is because the form designer cannot
> cope with creating calc fields in the constructor code and will delete
> any such code if you open the form in the designer.
>
>
> Bruce Beacham
>
> ********************************
> if file("tempsex.dbf")
>     delete table tempsex
> endif
>
> create table tempsex (name char(20), sex boolean)
> use tempsex
> generate 6
> use
>
> set proc to tempsex.wfm
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 14/07/2017
> //
> parameter bModal
> local f
> f = new tempsexForm()
> if (bModal)
>     f.mdi = false // ensure not MDI
>     f.readModal()
> else
>     f.open()
> endif
>
> class tempsexForm of FORM
>     with (this)
>        open = class::form_open
>        readmodal = class::form_readmodal
>        height = 16.0
>        left = 71.0
>        top = 0.0
>        width = 40.0
>        text = ""
>     endwith
>
>     this.QUERY1 = new QUERY(this)
>     with (this.QUERY1)
>        left = 21.0
>        width = 5.0
>        height = 1.0
>        sql = "select * from tempsex"
>        active = true
>     endwith
>
>     this.TEXTLABEL1 = new TEXTLABEL(this)
>     with (this.TEXTLABEL1)
>        height = 1.0
>        left = 7.1429
>        top = 5.4545
>        width = 17.1429
>        text = "Name the sex:"
>     endwith
>
>     this.ENTRYFIELD1 = new ENTRYFIELD(this)
>     with (this.ENTRYFIELD1)
>        height = 1.0909
>        left = 9.2857
>        top = 6.5455
>        width = 20.7143
>        picture = "XXXXXXXXXXXXXXXXX"
>     endwith
>
>     this.TEXTLABEL2 = new TEXTLABEL(this)
>     with (this.TEXTLABEL2)
>        height = 1.0909
>        left = 7.1429
>        top = 2.1818
>        width = 17.8571
>        text = "Name"
>     endwith
>
>     this.ENTRYFIELD2 = new ENTRYFIELD(this)
>     with (this.ENTRYFIELD2)
>        dataLink = form.query1.rowset.fields["name"]
>        height = 1.0909
>        left = 10.0
>        top = 3.2727
>        width = 20.0
>     endwith
>
>     this.PUSHBUTTON1 = new PUSHBUTTON(this)
>     with (this.PUSHBUTTON1)
>        onClick = class::PUSHBUTTON1_ONCLICK
>        height = 1.0909
>        left = 7.1429
>        top = 10.0909
>        width = 10.0
>        text = "Previous"
>     endwith
>
>     this.PUSHBUTTON2 = new PUSHBUTTON(this)
>     with (this.PUSHBUTTON2)
>        onClick = class::PUSHBUTTON2_ONCLICK
>        height = 1.0909
>        left = 22.1429
>        top = 10.0909
>        width = 10.0
>        text = "Next"
>     endwith
>
>     this.rowset = this.query1.rowset
>
>     FUNCTION form_open
>        if class::form_init()
>           super::open()
>        endif
>
>        return
>
>     FUNCTION form_readModal
>        if class::form_init()
>           super::readmodal()
>        endif
>
>        return
>
>     FUNCTION form_init
>
>        c = new field()
>        with (c)
>           fieldname = "cSex"
>        endwith
>        this.QUERY1.rowset.fields.add(c)
>        with (this.QUERY1.rowset.fields["cSex"])
>           canChange = class::SEX_CANCHANGE
>           beforeGetValue = class::SEX_BEFOREGETVALUE
>        endwith
>
>        with (this.QUERY1.rowset)
>           with (fields["cSex"])
>              canChange = class::CSEX_CANCHANGE
>              beforeGetValue = class::CSEX_BEFOREGETVALUE
>           endwith
>        endwith
>
>        with (this.ENTRYFIELD1)
>           dataLink = form.query1.rowset.fields["cSex"]
>        endwith
>
>        return true
>
>     function PUSHBUTTON1_onClick()
>        form.rowset.next(-1)
>        return
>
>     function PUSHBUTTON2_onClick()
>        form.rowset.next()
>        return
>
>     function cSex_beforeGetValue
>        local sex
>        if this.parent["sex"].value
>           sex = "Male"
>        else
>           sex = "Female"
>        endif
>
>        return (sex)
>
>     function cSex_canChange(newValue)
>        if newValue = "Male"
>           this.parent["sex"].value := true
>           this.parent.parent.save()
>        elseif newValue = "Female"
>           this.parent["sex"].value := false
>           this.parent.parent.save()
>        else
>           msgbox("Needs to be Male or Female.")
>        endif
>
>        return false
>
> endclass
>
>
> ********************************