You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

In these examples, the forms are named REFEX1 and REFEX2.
Main Form
FUNCTION options(*DIRECT)
BEGIN_COM role(*EXTENDS #PRIM_FORM) CAPTION('Main Form') HEIGHT(290) LEFT(318) TOP(128) WIDTH(386)

  • When you use REFERENCE(*DYNAMIC) you tell the application that an instance  of the form
  • #REFEX2 (referred to as #AddressForm) will be created when you get round to it, not when this main form is loaded.
  • This means that before you can use this new reference, you have to create it using a SET_REF command:
    DEFINE_COM class(#REFEX2) name(#AddressForm) reference(*dynamic)
    DEFINE_COM class(#PRIM_PHBN) name(#PHBN_ADDR) CAPTION('Show Address Form') DISPLAYPOSITION(1) LEFT(248) PARENT(#COM_OWNER) TABPOSITION(1) TOP(16) WIDTH(112)
    DEFINE_COM class(#PRIM_STBR) name(#STBR_1) DISPLAYPOSITION(2) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(239) WIDTH(378)
    DEFINE_COM class(#EMPNO.Visual) name(#EMPNO) DISPLAYPOSITION(3) HEIGHT(18) LEFT(22) MARGINLEFT(100) PARENT(#COM_OWNER) TABPOSITION(3) TOP(21) WIDTH(163)
    DEFINE_COM class(#PRIM_GRID) name(#GRID_1) DISPLAYPOSITION(4) HEIGHT(179) LEFT(24) NOTIFICATIONSTYLE(Default) PARENT(#COM_OWNER) SHOWBUTTONSELECTION(False) SHOWSELECTIONHIGHLIGHT(True) TABPOSITION(4) TOP(48) WIDTH(337)
    DEFINE_COM class(#PRIM_GDCL) name(#GDCL_1) DISPLAYPOSITION(1) PARENT(#GRID_1) SOURCE(#EMPNO) WIDTH(35)
    DEFINE_COM class(#PRIM_GDCL) name(#GDCL_2) DISPLAYPOSITION(2) PARENT(#GRID_1) SOURCE(#SURNAME) WIDTH(27) WIDTHTYPE(Remainder)
    EVTROUTINE handling(#com_owner.Initialize)
    SELECT fields(#GRID_1) from_file(PSLMST)
    ADD_ENTRY to_list(#GRID_1)
    ENDSELECT
    ENDROUTINE
    EVTROUTINE handling(#PHBN_ADDR.Click)
  • Create  an instance of the AddressForm. After this statement you will be in basically the same position as you would have been had
  • you simply used a normal DEFINE_COM without the dynamic reference:
    SET_REF com(#AddressForm) to(*create_as #refex2)
  • Now that an instance of the AddressForm exists, you can run the methods in it.  You invoke u_GetDetails passing in the employee
  • number and surname:
    INVOKE method(#AddressForm.u_GetDetails) U_WITHEMPNO(#EMPNO) U_WITHSURNAME(#SURNAME)
    ENDROUTINE
  • This event signalled from the AddressForm tells this form that it has closed:
    EVTROUTINE handling(#AddressForm.u_Detail_form_closed)
  • When the instance of the AddressForm closes, remove it from memory by setting the reference to it to*NULL.
  • This says remove anything related to AddressForm from memory.  In other words the form itself, the button
  • and the fields will all disappear from the system:
    SET_REF com(#AddressForm) to(*null)
    ENDROUTINE
    END_COM
    Address Form
    FUNCTION options(*DIRECT)
    BEGIN_COM role(*EXTENDS #PRIM_FORM) CAPTION('Address Form') HEIGHT(211) LEFT(320) TOP(112) WIDTH(405)
    DEFINE_COM class(#PRIM_STBR) name(#STBR_1) DISPLAYPOSITION(1) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(160) WIDTH(397)
    DEFINE_COM class(#EMPNO.Visual) name(#EMPNO) DISPLAYPOSITION(2) HEIGHT(18) LEFT(18) PARENT(#COM_OWNER) TABPOSITION(2) TOP(40) WIDTH(215)
    DEFINE_COM class(#SURNAME.Visual) name(#SURNAME) DISPLAYPOSITION(3) HEIGHT(19) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(3) TOP(20) WIDTH(324)
    DEFINE_COM class(#PRIM_PHBN) name(#PHBN_1) CAPTION('Close') DISPLAYPOSITION(4) LEFT(304) PARENT(#COM_OWNER) TABPOSITION(4) TOP(128)
    DEFINE_COM class(#ADDRESS1.Visual) name(#ADDRESS1) DISPLAYPOSITION(5) HEIGHT(19) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(5) TOP(72) WIDTH(363)
    DEFINE_COM class(#ADDRESS2.Visual) name(#ADDRESS2) DISPLAYPOSITION(6) HEIGHT(19) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(6) TOP(88) WIDTH(363)
    DEFINE_COM class(#ADDRESS3.Visual) name(#ADDRESS3) DISPLAYPOSITION(7) HEIGHT(19) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(7) TOP(104) WIDTH(363)
  • Define an event which will tell this form has closed
    DEFINE_EVT name(u_Detail_form_closed)
  • Published method which will get the #empno and #surname values from the main form, retreive the address information
  • from the PSLMST file and then show this form
    MTHROUTINE name(u_GetDetails)
    DEFINE_MAP for(*INPUT) class(#EMPNO) name(#u_WithEMPNO)
    DEFINE_MAP for(*INPUT) class(#SURNAME) name(#u_WithSURNAME)
    CHANGE field(#EMPNO) to('#U_WITHEMPNO.VALUE')
    CHANGE field(#SURNAME) to('#U_WITHSURNAME.VALUE')
    IF cond('#EMPNO *NE *BLANKS')
    FETCH fields(#ADDRESS1 #ADDRESS2 #ADDRESS3) from_file(PSLMST) with_key(#EMPNO)
    ENDIF
    INVOKE method(#COM_OWNER.ShowForm)
    ENDROUTINE
    EVTROUTINE handling(#PHBN_1.Click)
    INVOKE method(#com_owner.closeform)
    ENDROUTINE
    EVTROUTINE handling(#COM_OWNER.Closing) options(*NOCLEARMESSAGES *NOCLEARERRORS)
  • signal an event to the parent form telling that this form has closed
    SIGNAL event(u_detail_form_closed)
    ENDROUTINE
    END_COM

  • No labels