Subject Re: datalink controls
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 13 Jan 2018 08:43:24 +0200
Newsgroups dbase.getting-started
Attachment(s) swap_tables.wfm

On 2018-01-12 11:14 PM, Ken Mayer wrote:

>>> after change sql, should work with
>>> rowset.refreshControls()
>
>
> Are you deactivating the query? Try not doing that ... deactivating the
> query destroys the datalinks.

I have always been under the impression that one can only change the sql
property of a query if the query wasn't active.  Turns out I was wrong.
:-)

The attached little example works in dBASE 11.3 without any problems and
without having to use refreshcontrols().

Mervyn



if file('table_x.dbf')
//   drop table table_x
endif

if not file('table_x.dbf')
   create table table_x  (id autoinc,data1 character(5),data2 character(5),;
     data3 character(5))
    
  use table_x
  generate 5
  use
endif
if file('table_y.dbf')
//   drop table table_y
endif

if not file('table_y.dbf')
   create table table_y  (id autoinc,data1 character(5),data2 character(5),;
     data3 character(5))
    
  use table_y
  generate 5
  use
endif




** END HEADER -- do not remove this line
//
// Generated on 2018/01/12
//
parameter bModal
local f
f = new swap_tablesForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class swap_tablesForm of FORM
   with (this)
      height = 16.0
      left = 76.0
      top = 9.8182
      width = 57.2857
      text = ""
   endwith

   this.table = new QUERY()
   this.table.parent = this
   with (this.table)
      left = 1.0
      width = 6.0
      height = 1.0
      sql = 'select * from "table_x.DBF"'
      active = true
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      dataLink = form.table.rowset
      height = 7.0
      left = 4.0
      top = 3.5
      width = 43.0
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      dataLink = form.table.rowset.fields["data1"]
      height = 1.0
      left = 6.0
      top = 12.0
      width = 8.0
   endwith

   this.ENTRYFIELD2 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD2)
      dataLink = form.table.rowset.fields["data2"]
      height = 1.0
      left = 21.0
      top = 12.0
      width = 8.0
   endwith

   this.ENTRYFIELD3 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD3)
      dataLink = form.table.rowset.fields["data3"]
      height = 1.0
      left = 34.0
      top = 12.0
      width = 8.0
   endwith

   this.RADIOBUTTON1 = new RADIOBUTTON(this)
   with (this.RADIOBUTTON1)
      onChange = class::RADIOBUTTON1_ONCHANGE
      height = 1.0909
      left = 6.0
      top = 14.0
      width = 15.7143
      text = "table_x"
      group = true
      value = true
   endwith

   this.RADIOBUTTON2 = new RADIOBUTTON(this)
   with (this.RADIOBUTTON2)
      height = 1.0909
      left = 27.0
      top = 14.0
      width = 15.7143
      text = "table_y"
   endwith

   this.rowset = this.table.rowset

   function RADIOBUTTON1_onChange()
      if this.value = true
//         form.table.active = false
         form.table.sql = 'select * from "table_x.dbf"'
//         form.table.active = true
      else
//         form.table.active = false
         form.table.sql = 'select * from "table_y.dbf"'
//         form.table.active = true
      endif
      return

endclass