Passing an Object Ref
Martin Obongita
martin.obongita at yahoo.com
Wed Dec 21 13:28:59 UTC 2022
Hi Kelly,
In my form I have created this object
Calculate iCountryObjRef as $clib.$objects.oCountry.$newref()
The subtype of iCountryObjRef is oCountry ('oCountry' is an object class)
Then I pass this objref to the report class by running this command:
Do $clib.$reports.rListCountry.$open('*',iPrintList,iCountryObjRef) Returns iReportRef
The report class "rListCountry" is a subclass of "rSuperList"
What should be the subtype of the objref parameter "pCountryObjRef" created in the superclass that is receiving the object from the window class?
I have assigned the subtype of "pCountryObjRef" to "oCountry" in the report class "rListCountry".
If I step through, the pCountryObjRef in this report class is empty.
Hopefully my question is now clearer.
Martin
On Wednesday, December 21, 2022 at 04:08:09 PM GMT+3, Kelly Burgess <kellyb at montana.com> wrote:
Hi Martin,
>Does the receiving class have to calculate the $newref to the objclass or this will clear the reference to the referenced instance?
I'm not sure I understand your question.
$newref always creates a new instance and returns an object reference to it. Calculating another object reference variable as that object reference does not create another instance, it's just a copy of the pointer to the same object. While that object exists you can pass copies of the pointer around for different instances to use.
Andy's suggesting you use a task variable can simplify things - you instantiate at Startup_Task.$construct with a $newref and you dispose it in Startup_Task.$destruct with $deleteref, and you don't need to pass it as a parameter, you just use the one task variable from all instances.
If you've instantiated with $newref into an object reference task variable, and then you execute that same $newref again and overwrite the object reference, then the original instance is orphaned and hopefully garbage collected. And any copies of the first task object reference are stale and unusable.
Another way to work with a "singleton" object where you can keep the object references in instance variables is
If $clib.$objects.oTalker.$insts.$count()=0
Do $clib.$objects.oTalker.$newref() Returns iTalkerObjRef
Else
Do $clib.$objects.oTalker.$insts.$first().$objref Returns iTalkerObjRef
End If
That way you don't instantiate at startup time, the first instance that needs it creates the object, other instances can share it, and I think when there are no object references left pointing to it, Omnis will delete the object via garbage collection, so an explicit $deleteref isn't required. At least I've seen it work that way in simple tests, observing the $clib.$objects.xxx.$insts group in the notation inspector and seeing the one instance disappear after closing the last window instance that had an object reference to it.
Kind of a shotgun answer, but I wasn't sure what you're asking.
Kelly
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
More information about the omnisdev-en
mailing list