Achieving one code base with forms and windows
That code should work, I would never take that approach though unless
the object is some sort of generic window control object (which from
this code fragment it would seem it isn’t). I do have some such window
control objects which handle things like layout changes to my windows
where I have instance variables which are references to the window the
object manages for me and that does work fine. But these objects don’t
assume anything about my window, they will interrogate the window and
then apply their logic such as moving fields to cover empty space
because I’ve hidden fields and that sort of thing.
Remember my earlier post to you about explaining OO that objects work on
data held within, they should know nothing about the outside world. Here
you are creating an object that needs to know about the outside world,
about something very specific on this one window, which often leads to
bad design and hard to resolve bugs.
Now not knowing about what you are doing here my gut feeling says that
iLineItemsList should be based on a table class and your method should
be a method on that table class so it works on itself.
But assuming for a minute that an object class is indeed the right
solution, again turn the approach around.
Make iLineItemsList an instance variable of your object NOT of your window.
Move all the code that defines/loads/changes/etc this list into your
object so it has proper access to it. Then in your window simply set
your lists dataname to iMyObject.iLineItemsList
Now that last bit does lead to a bit of a contentious problem, Omnis
Studio treats all variables as public and are thus directly accessible
from the outside world. That is still something that is often frowned
upon because you can change those variables in ways the object can’t
govern and which may have unintended consequences.
For instance, one of your columns could be the gross amount of your
invoice over which 10% tax is calculated. This tax amount is then stored
in a tax column. If you rely on direct access to variables from the
outside world someone could change the gross amount without calculating
the tax, or someone could override the tax amount in ways that are illegal.
In this case you would want to treat your instance variables as private
or protected and add access methods to your object. So you would have a
“set gross amount” method that not only updates the gross amount column
but also calculate the tax for you. This way you protect and ensure that
your tax is ALWAYS correctly calculated when the gross amount changes.
You don’t need to rely on the programmer using your object later on to
remember how to calculate the tax.
The problem is that Omnis doesn’t know the concept of private and
protected for variables, only for methods, which is a shame so I go
through life always treating my instance variables as protected
(protected means that only the class or its subclasses can access the
variable directly and the outside world needs to call methods to access
You can in Omnis add a $lineItemsList and $lineItemsList.$assign method
as a getter and setter BUT this is the case in which I make an exception
to my own rules. Using a getter and setter for variables is great, you
can even change your dataname to iMyObject.$lineItemsList BUT doing so
with lists is very wasteful.
In this particular case practicality and performance win over “proper”
That all said, my example with calculating tax, owh yes, even with table
classes I’m exceedingly using that approach, having a $gross and
$gross.$assign method in my table class or object class, and using
ivMyRow.$gross or ivMyObject.$gross as my dataname on my window.
On 8/2/18 11:00 am, Das Goravani wrote:
> In line with the thread I am trying to put window code into an object for the first time in my work, and I’m surprised at how it’s not seeming to work
> Consider this line of code which is in the object which is instantiated in the window as an instance variable with subtype of actual object
> iwr=ref to the window
> If len(iwr.iLineItemsList.line_prod_num)
> iwr is a ref to the window, and iLineItemsList is an instance variable in the window and is a list, and line_prod_num is a field (column) in the list
> Isn’t it correct to code as I have above ? The chain of command is complete. I tried putting in $ivars and that didn’t help
> The window is live, I have entered something into that field in that list, it has Length
> It evaluates this as unTrue whereas it is True in fact
> Am I not doing it right?
> When I tab from the field it goes to the object method I specify for it and encounters the above line of code in the instantiated object (through subtype)
> Manage your list subscriptions at lists.omnis-dev.com
> Start a new message -> mailto:firstname.lastname@example.org