The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
this.BindingSource in v7.5 web custom code snippets
Posted: 09 Oct 08 2:32 PM
|
We have been upgrading some code form v7.2 and noticed that the 7.5 implementation of code snippets is different.
In 7.2 you were always supposed to check to ensure that this.BindingSource was not null before using it or trying to cast it to an entity type. However, in 7.5, this.BindingSource is NEVER null. It appears that this.BindingSource is initialized and all the properties of it are set to null.
Does anyone have suggestions on how to handle this in v7.5? We've gone through the 7.2 web coding training, but that's all out the window now. What a waste!
Thanks in advance. |
|
|
| |
|
Re: this.BindingSource in v7.5 web custom code snippets
Posted: 10 Oct 08 8:03 AM
|
Originally posted by Stephen Redmond
Would checking this.BindingSource.Current work for you? |
|
It's the same issue here. The object itself is never actually null. The object is being initialized by slx and every property associated with it is null. It's like they created a default constructor just to make a completely empty object. Seems sort of weird because it makes checking if your binding source or current binding source is null completely useless. |
|
|
|
Re: this.BindingSource in v7.5 web custom code snippets
Posted: 10 Oct 08 8:45 AM
|
I'm confused.
How is this a problem. What, exactly, are you trying to achieve and under what circumstances?
The fact that this.BindingSource is always populated is, to me, correct. If "this" is a bound page, then it will always have some kind of BindingSource, no? It is still valid to check that the BindingSource is null - it is good practice - but I don't see the problem.
Again, what, exactly, is the problem?
Stephen
|
|
|
|
Re: this.BindingSource in v7.5 web custom code snippets
Posted: 10 Oct 08 9:15 AM
|
Perhaps, it's more of a semantic issue than a practical issue. Here's a sample piece of code:
if (this.BindingSource.Current != null) { Sage.Entity.Interfaces.IAccount acct = this.BindingSource.Current as Sage.Entity.Interfaces.IAccount;
// get account name - could crash String s = acct.Account; }
The problem is that the object model will NEVER set this.BindingSource.Current to null (even though it's entity is really null). So, it will always allow you to cast this.BindingSource.Current as the interface that it is (IAccount in this example). Now, if you debug this code, you can find that referencing a property of this interface will return a null reference error.
Now, this seems silly to me - if the entity is really null, instead of allowing you to type cast it and attempt to reference a property, wouldn't you think that this.BindingSource.Current would be null? So if you pass the this.BindingSource.Current != null test, you should feel safe type casting and then referencing all the fields in the entity that have values within.
|
|
|
|
Re: this.BindingSource in v7.5 web custom code snippets
Posted: 10 Oct 08 11:14 AM
|
Hi,
If this.BindingSource.Current isn't an Account entity then your code line:
Sage.Entity.Interfaces.IAccount acct = this.BindingSource.Current as Sage.Entity.Interfaces.IAccount;
Will result in acct = null. This is the scenario that will occur when you use the same form to edit a related table for multiple entities. You cast Current and see which one isn't null to work with.
Your next line of code should be:
if (acct != null) { // get account name - could crash String s = acct.Account; }
Stephen www.slxmaster.com
|
|
|
|
Re: this.BindingSource in v7.5 web custom code snippets
Posted: 10 Oct 08 11:57 AM
|
I wish this were true.
Acct will NEVER be null. All of the properties of acct may be null, but the actual acct object there will never be null. It's really screwy and does not make sense.
Try adding a custom code snippet in 7.5 app architect for the onload action of adding a new account. Plug this code in and check it out. It's pretty disturbing.
|
|
|
|
Re: this.BindingSource in v7.5 web custom code snippets
Posted: 10 Oct 08 1:39 PM
|
OK, I vaguely understand what you are getting at.
There isn't a problem here. When you add a new Account, the system creates a new instance of the object with no values (how could it know what to fill them with). It is not that they system is populating the properties with Null, it is just not populating anything.
So the scenario that you have mentioned is not disturbing at all - it is FAD. Otherwise, how would you propose to write code to populate a default value?
Does that help ease your distubia?
Stephen www.slxmaster.com
|
|
|
| |
|