Παρασκευή 12 Φεβρουαρίου 2016

Test Local Modules in M2000 Groups (Objects)

Το παρακάτω έχει γραφτεί στα αγγλικά. Δείχνει πως γίνεται να έχουμε ένα αντικείμενο που να ελέγχει άλλα αντικείμενα σε ένα εξωτερικό πίνακα, έχοντας αναφορές σε αυτά τα αντικείμενα που είναι συνδεδεμένα με ισχνές αναφορές - δηλαδή αναφορές που δεν έχουν πραγματοποιηθεί, αλλά φυλάσσονται για αργότερα.
Δείχνω και ένα τρόπο να χειριστούμε ιδιωτική μεταβλητή, που κανονικά δεν προβάλλει προς τα έξω ένα αντικείμενο. Η διαδικασία αυτή υπήρχε πριν φτιαχτούν τα ιδιωτικά μέλη μιας ομάδας (αντικειμένου). Οπότε την άφησα ως έχει!


Form 60,40
Class object {
Private:
     screen=123
     \\ any Local member can't passed by reference
     Local id=0
     Local Dim handle$()
Public:
      myobject$
      Local Module Listme {
            read t$, &many
            If .id>0 then {
                  for i=0 to .id-1 {
                        If .handle$(i)<>"" then {
                               for .handle$(i) {
                                     Print .caption$
                                     If .yes then many++
                                     Print .x,.y,.w,.h, .yes
                               }
                         }
                  }        
            }
      }
      Function MyScreen {
            =.screen
      }
      Function TestMe {
            =eval(.myobject$.MyScreen())
      }
      Module LinkmeOnly {
            read where
            read .handle$(where)
      }
      Function AddMe {
            .id++
            dim .handle$(.id)
            =.id-1
      }
}
Class rectangle {
Private:
      myId
Public:
      x=10,y,w, h
      module rectangle {
            Over   '' duplicate the weak reference
            \\ make a temporary reference, store weak reference
            Read &A, A.myobject$
            This=A ' merge A to this
            While Match("G") {
                 READ This ' JOIN "THIS" WITH A GROUP
            }
      }
      module Display {
            Print "I use screen object", eval(.myobject$.MyScreen())
      }
      module refreshme {
            this=eval(.myobject$)
      }
      module UnlinkMe {
            link weak .myobject$ to b
            b.linkmeonly .myid, ""
      }
      module LinkMe {
            link weak .myobject$ to b
            .myId<=b.Addme()
            b.linkmeonly .myid, letter$
      }
}
Class clickable {
      yes=TRUE
}
Class button {
      caption$
}
\\ we make object our process object
Object=object()
Print Object.MyScreen() ' this is like a handler for screen 123
\\ now we make 10 rectangles, and they inherits Object
Dim myButtons(10)=rectangle(&Object, button(), clickable())
\\ so now it is time to put some values
for j=0 to 9 {
      For myButtons(j) {
            \\ function weak$() process  j to absolute value
            \\ so weak reference has only one reference inside
            .linkme weak$(myButtons(j))
            .x=100+j*5
            .y=200+j*5
            .w=1000
            .h=500
            .caption$="Button"+str$(j+1,"#")
            If Random(5)>1 then .yes=false
      }     
}
Print myButtons(1).TestMe(), myButtons(1).x
If valid(myButtons(1).yes) then Print myButtons(1).yes
Print myButtons(1).TestMe()
For j=0 to 9 {
      if random(10)<4 then myButtons(j).UnlinkMe
}
\\ lets say that Object change state to Screen++
\\ We can read a private variable linking to a new name
\\ with special READ FROM groupname
READ FROM Object, aScreen
\\ So now we can handle private screen
aScreen++
\\ Now myButon1.TestMe() reflect the change
Print myButtons(1).TestMe()
\\ but mybutton1 also has a screen too
for myButtons(1) {
      READ FROM This, , , , , , aScreen1 ' we have to know the  right position
      Print aScreen1 ' is 123
      .refreshme   ' so now we make another refresh
      Print aScreen1 ' is 124  
}



module Process {
      \\ If we make a reference then Listme can't exist because is local
      \\ but using absolute pointers we can call it like it is a global module
      \\ pointers are names in M2000
     Read pointer$
     howmany=0
     pointer$.ListMe "This is for Title", &howmany
     Print "Total", howmany
}
Process &Object


list   \\ we get a list of variables/arrays
modules ? \\ we get the loaded/created modules/functions


Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.