Subject Re: ALIAS
From Mervyn Bick <invalid@invalid.invalid>
Date Mon, 15 May 2017 09:17:05 +0200
Newsgroups dbase.getting-started

On 2017-05-14 6:51 PM, Mustansir A Ghor wrote:
> Dear Mervyn
> It was good to know from below program that objects can also be equated.
>  if form.grid1.datalink = form.country1.rowset

The ability to assign an object to an object property or a variable can
be very useful in cutting down on typing.

When working with fields in a rowset code can become quite unwieldy if
one is, say, copying fields from one table to another.  For example

   form.query1.rowset.fields['fld1'].value =
   form.query1.rowset.fields['fld2'].value =
   form.query1.rowset.fields['fld3'].value =

Instead of all this typing one can use

   r1 = form.query1.rowset.fields
   r2 = form.query2.rowset.fields

   r1['fld1'.value = r2['fld1'].value
   r1['fld2'.value = r2['fld2'].value
   r1['fld3'.value = r2['fld3'].value

> also i Would like to know if following syntax can be correct and what it implies if "class" is omitted in the pushbutton property

Try it and see what happens. :-)

Change the pushbutton's constructor code in the little example by
deleting  class::

     this.PUSHBUTTON1 = new PUSHBUTTON(this)
     with (this.PUSHBUTTON1)
        onClick = PUSHBUTTON1_ONCLICK
        height = 1.0909
        left = 25.4286
        top = 22.0
        width = 15.2857
        text = "Show other table"

Run the form and dBASE will tell you it can't find the variable

The :: symbol is the Scope Resolution Operator and the word before it
tells dBASE where to look for the function which is used as an event

The whole idea of Object Oriented Programming (OOP) is encapsulation and
in most cases your event handlers will be within your form's class
definition and this is where dBASE expects to be told to look.  There
can, however, be occasions where you want to use an event handler from a
different class and the scope resolution operator gives you this option.
  Ken discusses this in some detail in his dBASE book.

As you have removed the scope resolution dBASE "knows" you don't want to
use a function in the class definition as an event handler so it looks
for the function outside the class definition and can't find it.

Open the form in the sourcecode editor and copy the pushbutton's event
handler and past it BELOW the form's endclass statement.  Add a print
statement to this new function.

     function PUSHBUTTON1_onClick()
        if form.grid1.datalink = form.country1.rowset
           form.grid1.datalink = form.customers1.rowset
           form.grid1.datalink = form.country1.rowset


     function PUSHBUTTON1_onClick()
        ? 'Event handler outside the class definition'
        if form.grid1.datalink = form.country1.rowset
           form.grid1.datalink = form.customers1.rowset
           form.grid1.datalink = form.country1.rowset

If you run the form and click on the pushbutton the rowsets will change
but you will also see the string printed in the results panel which
indicates that it was the function outside the class definition which
was doing the work.

There may be occasions where you can use this technique but it goes
against the principles of OOP and should, therefore, be avoided.