Easier way to get the value of the key in Keyed collection?

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. 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
Yukiko Ikeo
Posts: 26
Joined: Fri Jun 09, 2017 11:58 pm

Easier way to get the value of the key in Keyed collection?

Post by Yukiko Ikeo »

Hi all,

product: Visual LANSA(Form)
version: V15(EPC150040)

Our customer says that they want to get Key value of Keyed collection in Evtroutine.
Their coding is as below:

Code: Select all

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(484) Clientheight(302) Componentversion(2) Left(441) Top(200)

Define_Com Class(#PRIM_KCOL<#PRIM_EVEF #STD_STRNG>) Name(#Fields) Style(Collection)

Define_Com Class(#DEPTMENT.Visual) Name(#DEPTMENT) Displayposition(1) Left(45) Parent(#COM_OWNER) Tabposition(1) Top(46)
Define_Com Class(#SECTION.Visual) Name(#SECTION) Displayposition(2) Left(45) Parent(#COM_OWNER) Tabposition(2) Top(99)
Define_Com Class(#EMPNO.Visual) Name(#EMPNO) Componentversion(1) Displayposition(3) Height(21) Left(45) Parent(#COM_OWNER) Tabposition(3) Top(149) Usepicklist(False) Width(245)

Evtroutine Handling(#com_owner.CreateInstance)

Set Com(#com_owner) Caption(*component_desc)

* Fields
#Fields<DEPT> <= #DEPTMENT
#Fields<SECT> <= #SECTION
#Fields<EMP> <= #EMPNO
Endroutine

Evtroutine Handling(#Fields<>.Changed) Com_Sender(#Sender)

For Each(#Current) In(#Fields) Key(#Key)
If ((#Current.Name = #Sender.Name))
#STD_STRNG := #Key
Leave
Endif
Endfor

Use Builtin(MESSAGE_BOX_ADD) With_Args(#STD_STRNG)
Use Builtin(MESSAGE_BOX_SHOW)

Endroutine

End_Com
- define keyd collection of #PRIM_EVEF
- in Evtroutine, get Key value of collection
- they know that it works as expected, but they want to know simpler and easier coding (if it exists).

Does anyone have any idea?
Any advise is appreciated.

Thanks in advance.
Best regards, Yukiko Ikeo
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Easier way to get the value of the key in Keyed collection?

Post by Dino »

Still trying to get the key, but you can know which field it is with #Sender.Name:

Code: Select all

Evtroutine Handling(#Fields<>.Changed) Com_Sender(#Sender)
#STD_STRNG := #Sender.Name

Use Builtin(MESSAGE_BOX_ADD) With_Args(#STD_STRNG)
Use Builtin(MESSAGE_BOX_SHOW)
Endroutine
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Easier way to get the value of the key in Keyed collection?

Post by Dino »

And found it! #STD_STRNG := #Fields.KeyOf<#Sender>

Code: Select all

Evtroutine Handling(#Fields<>.Changed) Com_Sender(#Sender)
#STD_STRNG := #Fields.KeyOf<#Sender>

Use Builtin(MESSAGE_BOX_ADD) With_Args(#STD_STRNG)
Use Builtin(MESSAGE_BOX_SHOW)
Endroutine
all the properties of the collection, applicable in this case to your collection #Fields are listed here: https://docs.lansa.com/15/en/lansa016/c ... M_KCOL.htm
Yukiko Ikeo
Posts: 26
Joined: Fri Jun 09, 2017 11:58 pm

Re: Easier way to get the value of the key in Keyed collection?

Post by Yukiko Ikeo »

Hi Dino,

Thank you for your reply.
It's great that you could find simpler and easier coding!

Thank you so much for your help :D
Best regards, Yukiko Ikeo
Post Reply