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.
-
jyoung
- Posts: 657
- Joined: Thu Jan 21, 2016 6:43 am
- Location: Oklahoma City, OK USA
Post
by jyoung » Sat Mar 02, 2019 2:36 am
If I define an object as such
Code: Select all
function options(*DIRECT)
begin_com role(*EXTENDS #PRIM_OBJT *LISTFIELDS #ListFields)
group_by name(#ListFields) fields(#HVBTC #HVPLCN #HVPLD #wk_Bool1)
define_pty name(TypeCode) get(*AUTO #HVBTC) set(*AUTO #HVBTC)
define_pty name(ControlNumber) get(*AUTO #HVPLCN) set(*AUTO #HVPLCN)
define_pty name(Description) get(*AUTO #HVPLD) set(*AUTO #HVPLD)
define_pty name(HasOptedIn) get(*AUTO #wk_Bool1) set(*AUTO #wk_Bool1)
end_com
How do you handle object equality?
Basically I want to store an instance of this object and then later compare that instance with another instance and see if they are the same.
such as
Code: Select all
if (#MyFirstObject = #MySecondObject)
* the two are the same
endif
In .NET, I could override Equals and GetHashCode or implement a Comparer. Is there something similar in LANSA or am I stuck doing property comparison?
Such as
Code: Select all
if (#CurrentPlan *IsNot *NULL)
if ((#CurrentPlan.TypeCode = #lItem.TypeCode) *AndIf (#CurrentPlan.ControlNumber = #lItem.ControlNumber))
* they are the same
endif
endif
-
Pablo
- Posts: 48
- Joined: Wed Dec 02, 2015 10:35 am
Post
by Pablo » Sat Mar 02, 2019 4:34 am
Hi Joe,
I assume you have a collection and some component that at one point you set to refer to the one you want to store as the current one:
Define_Com Class(#Prim_lcol<#MyListFieldsComponent>) Name(#ListEntries)
Define_Com Class(#MyListFieldsComponent) Name(#CurrentEntry) Reference(*DYNAMIC)
Then:
For Each(#Entry) In(#ListEntries)
If (#Entry *IsEqualTo #CurrentEntry)
* Your Logic Here
Endif
Endfor
Regards,
Pablo
-
jyoung
- Posts: 657
- Joined: Thu Jan 21, 2016 6:43 am
- Location: Oklahoma City, OK USA
Post
by jyoung » Sat Mar 02, 2019 5:15 am
That is what I was looking for.
Thanks!