Page 1 of 1

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

Posted: Tue Jul 26, 2022 12:32 pm
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

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

Posted: Wed Jul 27, 2022 3:25 am
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

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

Posted: Wed Jul 27, 2022 3:29 am
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

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

Posted: Wed Jul 27, 2022 10:22 am
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