Handling user-defined properties, events and methods, in a list cell

This forum allows developers to post programming tips and coding techniques that may be useful to other Visual LANSA developers. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Handling user-defined properties, events and methods, in a list cell

Post by Stewart Marshall » Wed Apr 06, 2016 11:02 am

Using a reusable part as a cell in a list allows a cell to do just about anything. However, the Design property of a column is defined as a Prim_panl, so it is not immediately obvious as to how user-defined Properties, Events and Methods in the part can be accessed at runtime.

Consider a column defined as below, using a reusable part #MyPart.

Code: Select all

Define_Com Class(#PRIM_LIST.Part) Name(#ColumnPart) Design(#MyPart)...
MyPart has the following features defined

Code: Select all

Define_Pty Name(MyProperty) Get(*Auto #Value)
Define_Evt Name(MyEvent) 

Mthroutine Name(MyMethod)
...
Endroutine
The CurrentItem property of a list column allows direct access to the instance of the part via the Part property. However, as this is necessarily defined as a Prim_panl, the editor will not recognise the features defined. The following line of code will therefore produce an error.

Code: Select all

#ColumnPart.CurrentItem.Part.MyMethod
However, by "casting" the Design instance as the correct class we can effectively tell the editor that it's OK, we know what we're doing, at runtime it will be the right class.

Code: Select all

(#ColumnPart.CurrentItem.Part *as #MyPart).MyMethod
Similarly, setting the MyProperty value would be as follows

Code: Select all

(#ColumnPart.CurrentItem.Part *as #MyPart).MyProperty := ABC
However, RDML can only monitor for events on a specific instance, so it's necessary to take a reference to the current part whenever focus changes. To do this, create a placeholder for the reference and then set it to the Part for the column's CurrentItem whenever an item gets or loses focus

Code: Select all

Define_Com Class(#MyPart) name(#CurrentItemPart) Reference(*Dynamic)

Evtroutine Handling(#List.ItemGotFocus)
#CurrentItemPart <= #ColumnPart.CurrentItem.Part *as #MyPart
Endroutine

Evtroutine Handling(#List.ItemLostFocus)
#CurrentItemPart <= *Null
Endroutine

Evtroutine Handling(#CurrentItemPart.MvEvent)

Endroutine

Attached is an import of a Web Page and Reusable Part. When a value is entered in a cell, it is immediately applied to a second column. When the clear button is clicked in the list, the Clear method in the part is invoked.
Attachments
UserDefinedFeatures.zip
(11.2 KiB) Downloaded 209 times
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

Post Reply