This step will define the component as a TreeDesign component and create an OnAdd method which is invoked when the form executes an ADD_ENTRY command on the Tree List control.
1. Switch to the Source tab. Extend the Begin_Com Role() keyword to include the highlighted code:
Begin_Com Role(*EXTENDS #PRIM_PANL *IMPLEMENTS #prim_tree.iTreedesign *LISTFIELDS #Listfields) Displayposition(1) Height(270) Left(0) Tabposition(1) Top(0) Width(500)
*implements #Prim_Tree.iTreeDesign means this component implements a User Defined Control which will be implemented as the row of a tree control.
*listfields #ListFields refers to a Group_By which defines fields to be mapped into this component when a row is added to the Tree List. i.e. when an instance of this component is created.
2. Define the ListFields Group_By:
Group_By Name(#Listfields) Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames #xEmployeeStreet #xEmployeeCity #xEmployeeState #xEmployeePostalCode #xEmployeeStartDate #xEmployeeTerminationDate #xDepartmentDescription #xDepartmentCode #xEmployeeImageThumbnail)
3. Define an OnAdd method to redefine the method in Prim_Tree.iTreeDesign. Add logic to perform the following:
Set the MoreLess cursor to the Windows Hand cursor
Set the panel initial Height based on MoreLess Top property plus MoreLess Height property
Set EmployeeName Caption to the form "GivenName, Surname (EmployeeIdentification)"
Set Street Caption to xEmployeeStreet
Set City Caption to xEmployeeCity
Set State Caption to xEmployeeState
Set PostCode Caption to xEmployeePostalCode
Set Department Caption to the form "Dept Description (Dept Code)"
If xEmployeeTerminationDate is not SQLNULL
Set StartDate ThemeDrawStyle property POOR
Set StartDate Caption to 'No longer employed - ' + xEmployeeTerminationDate
Else
Set StartDate ThemDrawStyle property to GOOD
Set StartDate Caption to 'Employed - ' + xEmployeeStartDate
End If
Set EmployeeImage FileName property to xEmployeeImageThumbnail
Note: The Label component has a default property of Caption. This statement sets the label's Caption:
#Label1 := #std_text
Your code should look like the following:
Mthroutine Name(OnAdd) Options(*REDEFINE)
* set cursor
#MoreLess.Cursor <= #SYS_APPLN.Cursors<Hand>
* set initial height
#COM_OWNER.Height := #MoreLess.top + #MoreLess.Height
* Set up caption for all labels
#EmployeeName := #xEmployeeGivenNames + ', ' + #xEmployeeSurname + '(' + #xEmployeeIdentification + ')'
#Street := #xEmployeeStreet
#City := #xEmployeeCity
#State := #xEmployeeState
#PostCode := #xEmployeePostalCode
#Department := #xDepartmentDescription + '(' + #xDepartmentCode + ')'
If (#xEmployeeTerminationDate.isnotsqlnull)
#StartDate.ThemeDrawStyle := POOR
#StartDate := 'No longer employed - ' + #xEmployeeTerminationDate.AsDisplayString( DDMMMCCYY )
Else
#StartDate.ThemeDrawStyle := GOOD
#StartDate := 'Employed - ' + #xEmployeeStartDate.AsDisplayString( DDMMMCCYY )
Endif
#EmployeeImage.filename := #xEmployeeImageThumbnail
Endroutine
Note: The ThemeDrawStyles POOR and GOOD are define in Theme xDemoTheme which will be applied to the form. xDemoTheme is part of the shipped Demonstration Materials (see Partition Initialize).
4. Create a Click event routine for the label MoreLess. Add logic to this routine to perform the following:
* Test current panel height
If Panel Height is greater than MoreLess Top + MoreLess Height
Set Panel Height property to MoreLess.Top + MoreLess.Height
Set MoreLess Caption to 'Show Details'
Else
Set Panel Height to Postcode.Top _ PostCode.Height
Set MoreLess Caption to 'Hide Details'
End IF
Your code should look like the following:
Evtroutine Handling(#MoreLess.Click)
If (#COM_OWNER.Height > (#MoreLess.top + #MoreLess.Height))
#COM_OWNER.Height := #MoreLess.Top + #MoreLess.Height
#MoreLess.caption := 'Show Details'
Else
#COM_OWNER.Height := #PostCode.top + #PostCode.Height
#MoreLess.Caption := 'Hide Details'
Endif
Endroutine
5. Compile the reusable part.