Object class in a Table class
Martin Obongita
martin.obongita at yahoo.com
Thu Nov 24 15:14:52 UTC 2022
Hi Scott,
I sent the library I was working on to Support UK.
They acknowledged that indeed the instance variable was crashing Omnis.
The problem was referred to Engineering.
But thanks be to God, I have wonderful people in this list who quickly found the solution is with object referencing.
I have also decided to use item references more often than instance variables.
The referencing of data looks 'cleaner code'.
Martin.
Sent from Yahoo Mail on Android
On Thu, 24 Nov 2022 at 17:58, Scotte Meredith<spomacguy at gmail.com> wrote:
Lesson I have learnt is I should use instance variables sparingly.
I'm glad the move to object references worked, however, I would have to disagree strongly about instance variables. I would certainly say to use class and task variables sparingly, but instance variables are the lifeblood of Omnis.
Omnis shouldn't have crashed in any case, and it warrants sending a sample in to support to take a look. There really shouldn't be anything we can do as programmers to crash the Studio core.
It's not the instance variables that caused the problem, but something else.
On Nov 24, 2022, at 5:25 AM, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
Hi @Kelly and @Phil and @Doug,
The object reference did the trick.
Omnis crashing when an object instance in a table super class is called, is now sorted.
Thank you so much.
Lesson I have learnt is I should use instance variables sparingly.
It's cool to know there are beautiful people out in space ready and willing to throw in a lifesaver.
Martin
On Thursday, November 24, 2022 at 02:55:19 AM GMT+3, Kelly Burgess <kellyb at montana.com> wrote:
Hi Martin,
I have never used object reference in my code.
This is because I don't understand how to use them.
I use instance variables of type object, sub type object class created in table classes, to call methods in object classes.
The way you do it now is you create an instance var of type Object and you assign the subtype to be your object class.
To change over to an Object Reference, you just change the variable type to Object Reference. You leave the subtype as it is, but for an object reference, the subtype is only used to tie the variable to an object class for purposes of using the Interface Manager - so it can show you the class's methods and properties. Assigning the subtype is optional - you don't have to commit to using the Object Reference with a particular class.
The second thing you need is a line in your $construct to create the object instance. With your current approach, the instance is created the first time the variable is referenced during code execution. With an object reference, the instance is created when you execute a $newref().
Calculate myObjRef as $clib.$objects.oMyObjClass.$newref()
The third thing you need is code in your $destruct to clean up the object.
If myObjRef.$validref()
Do myObjRef.$deleteref()
End If
Omnis has improved automatic garbage collection in the last few years, so maybe that $destruct cleanup is no longer needed, but it's good practice.
Object references are used just like item references, so you don't need to change any of your code that uses the variable. The problem with item refs is that sometimes when you pass one to another method, a new instance gets created and you lose whatever context the original instance carried with it. Object references can be passed around, kept in lists, etc. without that worry.
Kelly
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
Scotte Meredithspomacguy at gmail.com509/998-0991
More information about the omnisdev-en
mailing list