I have been trying to enable two or more classes to communicate with each other
in EB. "Communicate", means the ability to access and alter common data. I tried
lots of different ways, and found one acceptable way to do it. Basically, you
have to declare a global UDT. Each class that wishes to communicate, must
declare the same UDT. Then, the global UDT is passed into the classes, and back
to the program.
When the following console program runs, it prints
1 2
1 2
3 4
3 4
3 4
5 6
5 6
5 6
In the program, the two classes, CLASSA, and CLASSB, are identical except for
their names. But, I don't think that is significant. I think that the same
procedure should work for any two (or more) classes.
DTB.
'---------------------------------------------------------------
'EB CONSOLE PROGRAM = "INTERCLASSCOMM.EBA"
'---------------------------------------------------------------
TYPE TYPE1
INT I, J
ENDTYPE
'---------------------------------------------------------------
CLASS CLASSA
TYPE1 T1A
DECLARE RECEIVEDATA(TYPE1 T1P)
DECLARE MODIFYDATA(INT IP, INT JP)
DECLARE TRANSMITDATA(TYPE1 T1P)
DECLARE PRINTDATA()
ENDCLASS
SUB CLASSA::RECEIVEDATA(TYPE1 T1P)
T1A = T1P
ENDSUB
SUB CLASSA::MODIFYDATA(INT IP, INT JP)
T1A.I = IP
T1A.J = JP
ENDSUB
SUB CLASSA::TRANSMITDATA(TYPE1 T1P)
T1P = T1A
ENDSUB
SUB CLASSA::PRINTDATA()
PRINT T1A.I, " ", T1A.J
ENDSUB
'---------------------------------------------------------------
CLASS CLASSB
TYPE1 T1B
DECLARE RECEIVEDATA(TYPE1 T1P)
DECLARE MODIFYDATA(INT IP, INT JP)
DECLARE TRANSMITDATA(TYPE1 T1P)
DECLARE PRINTDATA()
ENDCLASS
SUB CLASSB::RECEIVEDATA(TYPE1 T1P)
T1B = T1P
ENDSUB
SUB CLASSB::MODIFYDATA(INT IP, INT JP)
T1B.I = IP
T1B.J = JP
ENDSUB
SUB CLASSB::TRANSMITDATA(TYPE1 T1P)
T1P = T1B
ENDSUB
SUB CLASSB::PRINTDATA()
PRINT T1B.I, " ", T1B.J
ENDSUB
'---------------------------------------------------------------
INT I
TYPE1 T1
CLASSA CA
CLASSB CB
T1.I = 1
T1.J = 2
PRINTGLOBALDATA()
CA.RECEIVEDATA(T1)
CA.PRINTDATA()
CA.MODIFYDATA(3, 4)
CA.PRINTDATA()
CA.TRANSMITDATA(T1)
PRINTGLOBALDATA()
CB.RECEIVEDATA(T1)
CB.PRINTDATA()
CB.MODIFYDATA(5, 6)
CB.PRINTDATA()
CB.TRANSMITDATA(T1)
PRINTGLOBALDATA()
CA.RECEIVEDATA(T1)
CA.PRINTDATA()
INPUT I
END
'---------------------------------------------------------------
SUB PRINTGLOBALDATA()
PRINT T1.I, " ", T1.J
ENDSUB
'---------------------------------------------------------------