Subject Re: Subforms
From Mervyn Bick <invalid@invalid.invalid>
Date Thu, 14 Aug 2014 10:05:57 +0200
Newsgroups dbase.getting-started

On Thu, 14 Aug 2014 04:58:31 +0200, Binoux <nonono@nonono.net> wrote:

>
> Hello Mervyn
>
> It works with pushbutton but you would have an example with entryfield  
> and
> table because I did not manage to make...

See if the example below give you any ideas.  It shows how to move data  
onto the subform and then move any changes back to the main form.

Mervyn.


********* Start of test_subedit.wfm **********
if file('test_sub.dbf')
   // drop table test_sub
endif

if not file('test_sub.dbf')
    create table test_sub  (id autoinc,Name character(15),data1  
numeric(10,2))

    insert into test_sub  (Name,data1) values ("Alpha",10.10)
    insert into test_sub  (Name,data1) values ("Bravo",20.20)
    insert into test_sub  (Name,data1) values ("Charlie",30.30)
    insert into test_sub  (Name,data1) values ("Delta",40.40)
    insert into test_sub  (Name,data1) values ("Echo",50.00)
endif

** END HEADER -- do not remove this line
//
// Generated on 2014/08/14
//
parameter bModal
local f
f = new test_subeditForm()
if (bModal)
    f.mdi = false // ensure not MDI
    f.readModal()
else
    f.open()
endif

class test_subeditForm of FORM
    with (this)
       onOpen = class::FORM_ONOPEN
       height = 16.0
       left = 21.0
       top = 10.8636
       width = 76.2857
       text = ""
    endwith

    this.TEST_SUB1 = new QUERY()
    this.TEST_SUB1.parent = this
    with (this.TEST_SUB1)
       left = 1.7143
       top = -0.0455
       sql = 'select * from "test_sub.DBF"'
       active = true
    endwith

    this.GRID1 = new GRID(this)
    with (this.GRID1)
       dataLink = form.test_sub1.rowset
       allowEditing = false
       height = 6.8182
       left = 8.8571
       top = 1.4545
       width = 58.5714
    endwith

    this.PUSHBUTTON1 = new PUSHBUTTON(this)
    with (this.PUSHBUTTON1)
       onClick = class::PUSHBUTTON1_ONCLICK
       height = 1.0909
       left = 30.4286
       top = 11.0455
       width = 15.2857
       text = "Open subform"
    endwith

    this.rowset = this.test_sub1.rowset

    function PUSHBUTTON1_onClick
       // pass values to objects on the subform and then open it
       form.sub.entryfield1.value =  
form.test_sub1.rowset.fields["name"].value
       form.sub.entryfield2.value =  
form.test_sub1.rowset.fields["data1"].value
       form.sub.open()
       return

    function form_onOpen
       set procedure to subedit.sfm
       form.sub = new subeditformForm(this)
       //Passing a title for the subform in the constructor code
       //in the line above doesn't work so it needs to be set
       //in the line below
       form.sub.text = "Edit record"
       return

endclass
********* End of test_subedit.wfm **********


******* Start of subedit.sfm ***************
class subeditformForm( oParent, cTitle ) of SUBFORM( oParent, cTitle )
    with (this)
       onClose = class::FORM_ONCLOSE
       height = 12.1818
       left = 23.4286
       top = 1.2727
       width = 37.8571
       text = ""
       mdi = true
    endwith

    this.PUSHBUTTON1 = new PUSHBUTTON(this)
    with (this.PUSHBUTTON1)
       onClick = class::PUSHBUTTON1_ONCLICK
       height = 1.0909
       left = 3.2857
       top = 7.3636
       width = 15.0
       text = "Save change"
    endwith

    this.PUSHBUTTON2 = new PUSHBUTTON(this)
    with (this.PUSHBUTTON2)
       onClick = class::PUSHBUTTON2_ONCLICK
       height = 1.0909
       left = 19.2857
       top = 7.3636
       width = 15.0
       text = "Abandon change"
    endwith

    this.ENTRYFIELD1 = new ENTRYFIELD(this)
    with (this.ENTRYFIELD1)
       height = 1.0909
       left = 3.2857
       top = 3.0
       width = 15.0
       value = "Entryfield1"
    endwith

    this.ENTRYFIELD2 = new ENTRYFIELD(this)
    with (this.ENTRYFIELD2)
       height = 1.0909
       left = 19.2857
       top = 3.0
       width = 15.0
       value = "Entryfield2"
    endwith


    function PUSHBUTTON1_onClick
    // Save any changes to the rowset on the main form
    // this = pushbutton1
    // this.parent = subeditformForm
    // this.parent.parent = test_subeditForm
    *
       this.parent.parent.test_sub1.rowset.beginedit()
       this.parent.parent.test_sub1.rowset.fields["name"].value =  
form.entryfield1.value
       this.parent.parent.test_sub1.rowset.fields["data1"].value =  
form.entryfield2.value
       this.parent.parent.test_sub1.rowset.save()
       form.close()
      */
       return

    function PUSHBUTTON2_onClick
       //abandon the changes by closing the form.
       form.close()
       return

    function form_onClose
       //When the subform closes set focus back to a specific
       //control on the main form ready for the next operation.
       //this.parent = test_subeditForm
       this.parent.grid1.setfocus()
       return

endclass
********** End of subedit.sfm *************

********* Start of subedit.wfm *************


// This form is not meant to be run on its own.
// The sourcecode is edited by hand or processed using
// by create_subform.wfm to create a subform
// which is called from test_subedit.wfm

** END HEADER -- do not remove this line
//
// Generated on 2014/08/14
//
parameter bModal
local f
f = new subeditformForm()
if (bModal)
    f.mdi = false // ensure not MDI
    f.readModal()
else
    f.open()
endif

class subeditformForm of FORM
    with (this)
       onClose = class::FORM_ONCLOSE
       height = 12.1818
       left = 23.4286
       top = 1.2727
       width = 37.8571
       text = ""
       mdi = true
    endwith

    this.PUSHBUTTON1 = new PUSHBUTTON(this)
    with (this.PUSHBUTTON1)
       onClick = class::PUSHBUTTON1_ONCLICK
       height = 1.0909
       left = 3.2857
       top = 7.3636
       width = 15.0
       text = "Save change"
    endwith

    this.PUSHBUTTON2 = new PUSHBUTTON(this)
    with (this.PUSHBUTTON2)
       onClick = class::PUSHBUTTON2_ONCLICK
       height = 1.0909
       left = 19.2857
       top = 7.3636
       width = 15.0
       text = "Abandon change"
    endwith

    this.ENTRYFIELD1 = new ENTRYFIELD(this)
    with (this.ENTRYFIELD1)
       height = 1.0909
       left = 3.2857
       top = 3.0
       width = 15.0
       value = "Entryfield1"
    endwith

    this.ENTRYFIELD2 = new ENTRYFIELD(this)
    with (this.ENTRYFIELD2)
       height = 1.0909
       left = 19.2857
       top = 3.0
       width = 15.0
       value = "Entryfield2"
    endwith


    function PUSHBUTTON1_onClick
    // Save any changes to the rowset on the main form
    // this = pushbutton1
    // this.parent = subeditformForm
    // this.parent.parent = test_subeditForm
    *
       this.parent.parent.test_sub1.rowset.beginedit()
       this.parent.parent.test_sub1.rowset.fields["name"].value =  
form.entryfield1.value
       this.parent.parent.test_sub1.rowset.fields["data1"].value =  
form.entryfield2.value
       this.parent.parent.test_sub1.rowset.save()
       form.close()
      */
       return

    function PUSHBUTTON2_onClick
       //abandon the changes by closing the form.
       form.close()
       return

    function form_onClose
       //When the subform closes set focus back to a specific
       //control on the main form ready for the next operation.
       //this.parent = test_subeditForm
       this.parent.grid1.setfocus()
       return

endclass
*********** End of subedit.wfm **************


Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0