Subject Re: Form to Form
From Mervyn Bick <invalid@invalid.invalid>
Date Thu, 11 May 2023 13:02:23 +0200
Newsgroups dbase.getting-started

On 2023/05/10 23:33, Peter wrote:
> Unfortunately, this does not work.
> First I get message that "form cannot be MDI".
> Then the form.patient.rowset.fields["pat_no"] does not seem to work.
> Here is what I put in:

You need to rearrange things a bit.  As I don't have the actual tables
this is not tested.  (Standard CYA disclaimer in case it doesn't
actually work. :-) )

Comments in line below.

As an aside, it makes for a tidier, and more readable, presentation when
you copy and paste code into a message if you tick the "Tab Inserts
Spaces" block in the Editor tab of the Source Editor Properties dialogue.

>     function PBGOTO_onClick()
> /*                if isalpha(form.ENTRYFIELD1.value)
>                    form.entryfield1.value = form.patient1.rowset.fields["pat_no"].value+" -- "+;
>                                         TRIM(form.patient1.rowset.fields["lname"].value)+", " + ;
>                                         form.patient1.rowset.fields["fname"].value
>                 else
>                         form.entryfield1.value = form.patient1.rowset.fields["pat_no"].value
>                 endif
>                 */
........

>                 form.close()
>                 return

I assume the following is the onOpen event handler in the editpastest form.

As the rowpointer will be set in memory before the form opens this event
handler is no longer needed.


>     function form_onOpen()
>                 if type("form.mGoto") == "N"
>                         form.query1.rowset.findkey(mGoto)
> //This next line shows INCORRECT value of pat_no.
>                         msgbox("Value of pat_no: " + form.query1.rowset.fields["pat_no"].value)
> //This line shows error: Unrecognized command verb
>                         form.query1.rowset.fields["pat_no"].value
>                 else
>                         msgbox("Type of mGoto: "+type("form.mGoto"))
>                 endif


With an MDI form opened with the readmodal() method processing stops
until the editpattest form is closed.  There is then no problem with
releasing an nulling the form in the PBGO_onClick function.

With a SDI form you would use the open() method, not readmodal(), and,
as processing doesn't stop, you can't release and null the editpastest
form in the PBGOTO_onClick function.

Create the instance of the editpattest form in memory in the main form's
onOpen event handler and save it in a user-defined property of the form.

   function form_onOpen()
     set procedure to editpattest.wfm
     form.edit_pat_test = new editpattestForm()
     return

  Do the house keeping in the main form's onClose event handler.

   function form_onClose()
     //Because it is possible to close the main form with multiple
     //copies of editpastest open force their closure and then do
     // the house keeping.
     local f
     f = findinstance("editpastestForm") //The actual classname
     do while not empty(f)
       f.close()
       f := findinstance("editpastestForm", f)
     enddo
     //If you null the property you shouldn't need to release the form.
     form.edit_pat_test = null
     return.


   function PBGOTO_OnClick()
     //Save the pat_no value to a user-defined property of editpastest
     //in memory
     form.edit_pat_test.Goto = class::get_pat_no() //Discussed later.
     if form.edit_pat_test.goto <> null
       //Set the rowset pointer in editpastest
       //I assume the query name in editpattest is also patient1. If not,
       //use the correct query name.
       form.edit_pat_test.patient1.rowset.goto(form.edit_pat_test.goto)
       form.edit_pat_test.open()
     else
       msgbox('Invalid patient number or name')
     endif
     return


   function get_pat_no()
     //As the user can enter either the patient number or the patient
     //name you need some mechanism for making sure the user enters a
     //valid value.
     local nRet
     nRet = null // If a record is found this will be overwritten

     // Code needed here to verify selection.

     return nRet

    return

We're heading into a 4 hour power outage so further discussion will need
to wait until tomorrow


Mervyn