Tips_tutorials   >   Studio104   >   Parent Window
A parent window is a window class which contains one or more subwindow fields. The subwindow is considered a child window of the parent window.
A subwindow field is a special window object which allows you to instantiate a window class inside of another window class instance.
A child window knows nothing about the world outside of itself. The child window doesn't even know who its parent is. The parent is responsible to inform the child who its parent is.
Communication between parent and child window instances is accomplished by sending messages via the public class methods of the parent and child windows.
In this section we will create a parent window class with two subwindows. Each subwindow will be an instance of wHeadedList. One subwindow will display a list of the countries, the other subwindow class will display a list of states/provs for the selected country.To create the parent window class:
; Define the list binding it to the table class.
Do iCountriesList.$definefromsqlclass('tCountry')
; Set the session object in the list variable so that the SQL statements will be issued to that session's database.
Do iCountriesList.$sessionobject.$assign($ctask.dbsessionobj)
; Define the list binding it to the table class.
Do iStateprovsList.$definefromsqlclass('tStateprov')
; Set the session object in the list variable so that the SQL statements will be issued to that session's database.
Do iStateprovsList.$sessionobject.$assign(dbsessionobj)
Quit method kTrue
; Register this window as the parent.
Do irswCountries.$setParentRef($cinst) Returns FlagOK
If FlagOK
; Set a reference to the data list variable.
Do irswCountries.$setDataListRef(iCountriesList) Returns FlagOK
If FlagOK
; Get a reference to the list object.
Do irswCountries.$:ListObjRef() Returns rListObj
; Set the list object properties.
Do rListObj.$name.$assign('CountriesList')
Do rListObj.$colcount.$assign(1)
Do rListObj.$columnnames.$assign('Country')
Do rListObj.$calculation.$assign('irDataList.CountryName')
End If
End If
Quit method FlagOK
; Register this window as the parent.
Do irswStateprovs.$setParentRef($cinst) Returns FlagOK
If FlagOK
; Set a reference to the data list variable.
Do irswStateprovs.$setDataListRef(iStateprovsList) Returns FlagOK
If FlagOK
; Get a reference to the list object.
Do irswStateprovs.$:ListObjRef() Returns rListObj
; Set the list object properties.
Do rListObj.$name.$assign('StateprovsList')
Do rListObj.$colcount.$assign(2)
Do rListObj.$columnnames.$assign('State/Prov,Abbrev')
Do rListObj.$calculation.$assign('con(irDataList.StateProvName,kTab,irDataList.StateProvAbbrev)')
End If
End If
Quit method FlagOK
Do iCountriesList.$getAllRecords() Returns FlagOK
Quit method FlagOK
If iCountriesList.$line
; Fetch the state/prov records linked to the selected country.
Calculate SQLText as con("WHERE Country_fkey = ",iCountriesList.Country_pkey)
Do iStateprovsList.$select(SQLText) Returns FlagOK
If FlagOK
Do iStateprovsList.$fetch(kFetchAll) Returns FlagOK
End If
; Redraw the state/prov subwindow.
Do irswStateprovs.$redraw()
End If
Quit method FlagOK
Do method constructDefineLists Returns FlagOK
If FlagOK
Do method constructSubWin_Countries Returns FlagOK
If FlagOK
Do method constructSubWin_Stateprovs Returns FlagOK
If FlagOK
Do method buildCountriesList Returns FlagOK
If FlagOK
Do method buildStateprovsListForCurrCountry Returns FlagOK
End If
End If
End If
End If
If not(FlagOK)
Do errhndlr.$promptonceLastError()
End If
Quit method FlagOK
Calculate FlagOK as kTrue ;; Preset flag to true
Switch low($cobj().$name)
Case 'countrieslist'
If pEventCode=evClick
Do method buildStateprovsListForCurrCountry Returns FlagOK
End If
Case 'stateprovslist'
; Do nothing.
End Switch
Quit method FlagOK
We will now add the subwindow fields to the wCountryStateprovContainer window class.
Set reference irswCountries to $cfield
Set reference irswStateprovs to $cfield
We are just about ready to test the wCountryStateprovContainer window.
In order to open and instance of the window class we will add a menu line to the main menu.
; Find and open an instance of the town/city list window class.
Calculate ClassName as 'wCountryStateProvContainer'
Do $clib.$windows.$findname(ClassName) Returns rClass
If isnull(rClass)
OK message [sys(85)] (Icon) {Unable to find the window class '[ClassName]'.}
Else
Do rClass.$openonce('*') Returns rWin
If isnull(rWin)
OK message [sys(85)] (Icon) {Unable to open an instance of the window class [ClassName].}
End If
End If
Quit method rWin
We are now ready to test the parent window.
The following is an overview of the sequence of events that occur when the parent window is instantiated.
A better alternative would be to add a public method to wHeadedList for setting the headed list properties. e.g. $setListObjColumns(pDataListColNamesCSV,pColNamesCSV,pColAlignCSV) The method would then parse the CSV strings and set the $colcount, $columnnames, $calculation properties and set the alignment for each column.