Subject Re: text object on the fly
From Mervyn Bick <invalid@invalid.invalid>
Date Tue, 8 Jun 2021 11:04:20 +0200
Newsgroups dbase.getting-started
Attachment(s) test_loop.wfm

On 2021/06/07 21:37, Mustansir Ghor wrote:
> Dear All
>
> I wish to assign a function to an event of text object in the following manner
>
>   for m = 1 to 6
>      for n = 1 to 7
>         mtname = "form."+"TW"+str(m,1)+"D"+str(n,1)+".onLeftDblClick=class::tshift_select"
>           ?mtname
>           &mtname.
>      endfor
>   endfor
>
>   function Tshift_select ()
>          if empty(this.text)
>           return
>          endif
>          this.fontsize=8
>          this.text+=form.qshift.rowset.fields["name"].value
>          this.alignhorizontal=1
>         return
>
>                 
> I am attaching the resulting mtname string as Capture1 and the error message as Capture.
>
> I wonder , Is my error a syntatical one or logical one. Or such a doing not possible.

Firstly, it is possible.  It's a very convenient way of attaching the
same event handler to multiple objects.

The function, Tshift_select, needs to be within the class definition.

A little example form is attached.

Mervyn.




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

class test_loopForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 16.0
      left = 46.1429
      top = 0.0455
      width = 56.5714
      text = ""
   endwith

   this.DBASESAMPLES1 = new DATABASE(this)
   with (this.DBASESAMPLES1)
      left = 12.0
      width = 11.0
      height = 1.0
      databaseName = "DBASESAMPLES"
      active = true
   endwith

   this.FISH1 = new QUERY(this)
   with (this.FISH1)
      left = 6.0
      width = 3.0
      height = 1.0
      database = form.dbasesamples1
      sql = "select * from FISH.DBF"
      active = true
   endwith

   this.TW1D1 = new TEXT(this)
   with (this.TW1D1)
      height = 1.0
      left = 7.5714
      top = 4.1364
      width = 43.8571
      border = true
      text = "Text1"
   endwith

   this.TW1D2 = new TEXT(this)
   with (this.TW1D2)
      height = 1.0
      left = 7.5714
      top = 6.5455
      width = 43.8571
      border = true
      text = "Text2"
   endwith

   this.TW2D1 = new TEXT(this)
   with (this.TW2D1)
      height = 1.0
      left = 7.5714
      top = 9.1364
      width = 43.8571
      border = true
      text = ""
   endwith

   this.TW2D2 = new TEXT(this)
   with (this.TW2D2)
      height = 1.0
      left = 7.5714
      top = 12.1818
      width = 43.8571
      border = true
      text = "Text4"
   endwith

   this.rowset = this.fish1.rowset

   function form_onOpen()
       clear
      for m = 1 to 2
         for n = 1 to 2
            mtname ="form."+"TW"+str(m,1)+"D"+str(n,1)+".onLeftDblClick=class::tshift_select"
            ?mtname
            &mtname.
         endfor
      endfor        
      return

    function Tshift_select ()
       if empty(this.text)
         return
       endif
       this.fontsize=8
       this.text+=form.FISH1.rowset.fields["name"].value
       this.alignhorizontal=1
      return

endclass