To see how forms can inherit from each other, create a form to be used as the ancestor for other forms. The ancestor form will have a File menu and a status bar:
You can copy the Source for the Ancestor Form and paste it to a form and compile it. In this example you call the ancestor form EOEXAM01.
When EOEXAM01 is run, you can see it has a File menu with three options and a status bar showing the current user, date and time.
The form contains a timer which updates the time every five seconds.
It also contains event routines for the File menu options which display message boxes. For example, when the Exit option is selected the message box asks to confirm the action:
Source for the Ancestor Form
Source for the Ancestor Form
***************************************************
*
* COMPONENT: STD_FORM
*
***************************************************
FUNCTION OPTIONS(*DIRECT)
BEGIN_COM LEFT(340) MENUBAR(#MBAR_1) TOP(132) VISUALSTYLE(#VS_NORM)
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(1) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(270) WIDTH(492)
DEFINE_COM CLASS(#USER.Visual) NAME(#USER) DISPLAYPOSITION(1) HEIGHT(18) LEFT(285) MARGINLEFT(0) PARENT(#STBR_1) READONLY(True) TABPOSITION(1) TABSTOP(False) TOP(4) WIDTH(71)
DEFINE_COM CLASS(#DATE.Visual) NAME(#DATE) DISPLAYPOSITION(2) HEIGHT(18) LEFT(358) MARGINLEFT(0) PARENT(#STBR_1) READONLY(True) TABPOSITION(2) TABSTOP(False) TOP(4) WIDTH(61)
DEFINE_COM CLASS(#TIME.Visual) NAME(#TIME) DISPLAYPOSITION(3) HEIGHT(18) LEFT(421) MARGINLEFT(0) PARENT(#STBR_1) READONLY(True) TABPOSITION(3) TABSTOP(False) TOP(4) WIDTH(54)
DEFINE_COM CLASS(#PRIM_TIMR) NAME(#TIMER) INTERVAL(5000)
DEFINE_COM CLASS(#PRIM_MBAR) NAME(#MBAR_1) PARENT(#COM_OWNER)
DEFINE_COM CLASS(#PRIM_MITM) NAME(#MITM_1) CAPTION('File') DISPLAYPOSITION(1) PARENT(#MBAR_1)
DEFINE_COM CLASS(#PRIM_SMNU) NAME(#SMNU_1) PARENT(#MITM_1)
DEFINE_COM CLASS(#PRIM_MITM) NAME(#MITM_FILE_OPEN) CAPTION('Open') DISPLAYPOSITION(1) PARENT(#SMNU_1)
DEFINE_COM CLASS(#PRIM_MITM) NAME(#MITM_FILE_CLOSE) CAPTION('Close') DISPLAYPOSITION(2) PARENT(#SMNU_1)
DEFINE_COM CLASS(#PRIM_MITM) NAME(#MITM_EXIT) CAPTION('Exit') DISPLAYPOSITION(3) PARENT(#SMNU_1)
* Initialize the details on th status bar
EVTROUTINE HANDLING(#Com_Owner.Initialize) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Change #User *User
Change #Date *Date
Change #Time *Time
ENDROUTINE
* Update the time on the status bar every 5 seconds (5000 milliseconds)
EVTROUTINE HANDLING(#TIMER.Tick) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Change #Time *Time
ENDROUTINE
* Handle Exit request by attempting to close the form
EVTROUTINE HANDLING(#MITM_EXIT.Click) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Invoke #Com_Self.CloseForm
ENDROUTINE
* Handle file open menu item by invoking the "HandleFileOpen" method
EVTROUTINE HANDLING(#MITM_File_Open.Click) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Invoke #Com_Self.HandleFileOpen
ENDROUTINE
* Handle file close menu item by invoking the "HandleFileClose" method
EVTROUTINE HANDLING(#MITM_File_Close.Click) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Invoke #Com_Self.HandleFileClose
ENDROUTINE
* Handle a request to close the form by getting a confirmation
EVTROUTINE HANDLING(#Com_Owner.Closing) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS) Action(#AfterCloseAction)
Use Message_Box_Show (okCancel Ok Info #Com_Self.Name 'Are you sure you want to close the form?') (#Std_Obj)
If '#Std_Obj = Cancel'
Set #AfterCloseAction Value(None)
Endif
ENDROUTINE
* Default method "HandleFileOpen". Typically this is redefined by a descendant
Mthroutine HandleFileOpen
Use Message_Box_Show (ok Ok Info #Com_Owner.Name 'Ancestor HandleFileOpen method invoked') (#Std_Obj)
Endroutine
* Default method "HandleFileClose". Typically this is redefined by a descendant
Mthroutine HandleFileClose
Use Message_Box_Show (ok Ok Info #Com_Owner.Name 'Ancestor HandleFileClose method invoked') (#Std_Obj)
Endroutine
END_COM