Subject Re: Subform canClose
From Mervyn Bick <invalid@invalid.invalid>
Date Mon, 8 Mar 2021 15:53:10 +0200
Newsgroups dbase.getting-started
Attachment(s) neu.wfmcreate_subform.wfm

On 2021/03/08 13:54, Peter Hegelbach wrote:
> Hi Andy
>
> I mean it just the other way around. I just want to prevent someone from
> closing the subform.
>
> It's ok if the mainform is closed. then the subform should be closed too.

Set the subform's midi property and sysMenu properties false.  A revised
version of your test form is attached.

Using subforms has it's place but, as dBASE doesn't provide a designer
for subforms, one has to create a normal form in the designer and the
manually edit the source code.

One needs to remove the "bootstrap" code change

class sub_neuForm of FORM

to

class sub_neuForm( oParent, cTitle ) of SUBFORM( oParent, cTitle )

This is all very well until one needs to make changes to the subform in
the designer.  Then one has to manually put the header and bootstrap
code back and replace the class definition line.  It can be done but
it's time consuming and it becomes a nuisance.

I created a little form to take a standard .wfm file and turn it into a
subform.  The only proviso is that the .wfm file name must start with
sub_   If changes are needed make them in sub_whatever.wfm and recreate
sub_whatever.sfm.

To use a subform create an instance of the subform in a user-defined
property of the main form.  The form's onOpen event handler is as good a
place as any


    set procedure to sub_whatever.sfm
    this.oSub = new sub_whateverForm(this)

To open the subform

    form.oSub.open()

Mervyn.












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

class neuForm of FORM
   with (this)
      canClose = class::FORM_CANCLOSE
      onOpen = class::FORM_ONOPEN
      metric = 6        // Pixels
      height = 250.0
      left = 100.0
      top = 80.0
      width = 600.0
      text = "Testform"
   endwith

    function form_onOpen
        this.sub_neu = new sub_neuForm(this)
         form.sub_neu.open()
        return
      
   function form_canClose
        // do my things
        form.close()
        return

endclass

class sub_neuForm( oParent, cTitle ) of SUBFORM( oParent, cTitle )
   with (this)
      height = 7.2273
      left = 0.4286
      top = 0.5455
      width = 50.0
      text = ""
      mdi = false
      sysMenu = false
   endwith
endclass





** END HEADER -- do not remove this line
//
// Generated on 2008/10/20
//
parameter bModal
local f
f = new create_subformForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class create_subformForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 16.0
      left = 70.2857
      top = 6.6818
      width = 40.0
      text = "Create Sub-form"
   endwith

   this.COMBOBOX1 = new COMBOBOX(this)
   with (this.COMBOBOX1)
      onChange = class::COMBOBOX1_ONCHANGE
      height = 1.0
      left = 5.2857
      top = 1.7727
      width = 29.4286
      style = 1        // DropDown
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      height = 1.0
      left = 5.1429
      top = 11.1818
      width = 29.5714
      value = ""
   endwith

   this.TEXTLABEL1 = new TEXTLABEL(this)
   with (this.TEXTLABEL1)
      height = 1.0
      left = 7.1429
      top = 9.3636
      width = 27.7143
      text = "Sub-form name (Edit if required)"
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.0909
      left = 11.5714
      top = 13.4545
      width = 15.2857
      text = "Create Sub-form"
   endwith


   function COMBOBOX1_onChange
      form.entryfield1.value = substr(form.combobox1.value,1,at('.',form.combobox1.value))+"sfm"

      return

   function form_onOpen
   clear
      form.combobox1.value = "Select a form to convert"
      aFullDir = new array()
      aNames = new array()
      aDir(aFullDir,"sub*.wfm")
      for n = 1 to aFullDir.size / 5
         if not "BACKUP"$upper(aFullDir[n,1])
            aNames.add(aFullDir[n,1])
         endif
      next    
      form.combobox1.datasource = 'array aNames'
      return

   function PUSHBUTTON1_onClick
      form.subname = form.entryfield1.value
      cfIn = form.combobox1.value
      cfOut =  form.subname
      fIn  = new File()
      fOut = new File()
      fIn.open(cfIn)
      fOut.create(cfOut)
      cRead = ""
      do while not "CLASS"$upper(cRead)
         cRead = fIn.readln()
      enddo
      cRead = stuff(cRead,at(" ",cRead,2),0,"( oParent, cTitle )")
      cRead = stuff(cRead,at("OF FORM",upper(cRead)),7,"of SUBFORM( oParent, cTitle )")
      fOut.puts(cRead)
      do while not fIn.eof()
          fOut.puts(fIn.readln())
      enddo
      fIn.close()
      fOut.close()
      return

endclass