StrataFrame Forum

Custom property problem (I think).

http://forum.strataframe.net/Topic13021.aspx

By Peter Jones - 12/13/2007

Hi Guys,

I wonder if you can throw a bit of light into this problem which I believe has something to do with custom fields in a BO. I have the following error in business object "boPUN_New" when I open up the form in the IDE that contains the BO. I can close the form and generally mess around until the form opens and I can see it the designer. boPUN_New is the datasource in a grid and I can see all the fields except my custom fields. I've used custom fields before so I have a template to follow and, as best as I can see, I've created them in this BO in the same manner as I've created them in other BO's. I've been messing around with this all day now and I'm getting no where - hopefully you can offer an insight that will help me make some progress...

TIA - Peter

Object reference not set to an instance of an object.
Hide    

at MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor..ctor(String PropertyName, Type PropertyOwner)
at BOInventory.boPUN_New.GetCustomBindablePropertyDescriptors() in C:\TMSRedevelopment\TMS\BOInventory\boPUN_New.vb:line 202
at MicroFour.StrataFrame.Business.BusinessLayer.InternalGetAdditionalPropertyDescriptors()
at MicroFour.StrataFrame.Business.BusinessLayer..ctor()

The variable 'BoPUN_New1' is either undeclared or was never assigned.

Hide    Edit

at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
By Trent L. Taylor - 12/14/2007

You did not add the attributes to your custom properties as well as the Reflection property descriptors.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Runtime.Serialization
Imports MicroFour.StrataFrame.Business
Imports MicroFour.StrataFrame.Security
Imports MicroFour.StrataFrame.UI.Windows.Forms
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.IO

Public Class CustomersBO
    Inherits MicroFour.StrataFrame.Business.BusinessLayer
#Region " Customer Properties "
    ''' <summary>
    ''' Customer First Name
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("Full Name"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property cust_FullName() As System.String
        Get
            Return Me.cust_LastName & ", " & Me.cust_FirstName
        End Get
        Set(ByVal value As System.String)
            '-- Establish Locals
            Dim laParts() As String = value.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
            cust_FirstName = laParts(1)
            cust_LastName = laParts(0)
        End Set
    End Property


    ''' <summary>
    ''' This provides a property descriptor that is used for reflection.  If you have more than
    ''' one custom property, then create another entry in the array that is being returned.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()
        Return New FieldPropertyDescriptor() {New ReflectionPropertyDescriptor("cust_FullName", Me.GetType())}
        'Return New FieldPropertyDescriptor() {New ReflectionPropertyDescriptor("cust_FullName", Me.GetType()), _
        '                                      New ReflectionPropertyDescriptor("AnotherField", Me.GetType())}
    End Function
#End Region
End Class

By Peter Jones - 12/14/2007

Hi Trent,

Thanks for the response but I don't think that's the case. However would you mind casting your eyes over the code - maybe you can spot an error that I can't see. My set of Imports wasn't exactly the same as your example but I added in those I was missing (just in case) but that didn't make any difference.

Cheers, Peter


#Region "Custom Fields"

    ''' <summary>
    ''' OperatorName
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("OperatorName"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public ReadOnly Property [Product]() As System.String
        Get
            Dim loValue As Object
            loValue = Me.CurrentRow.Item("OperatorName")
            If loValue Is DBNull.Value Then
                Return String.Empty
            Else
                Return CType(loValue, System.String)
            End If
        End Get
    End Property

    ''' <summary>
    ''' INIDescription
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("INIDescription"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public ReadOnly Property [INIDescription]() As System.String
        Get
            Dim loValue As Object
            loValue = Me.CurrentRow.Item("INIDescription")
            If loValue Is DBNull.Value Then
                Return String.Empty
            Else
                Return CType(loValue, System.String)
            End If
        End Get
    End Property

    ''' <summary>
    ''' INIMaxHides
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("INIMaxHides"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public ReadOnly Property [INIMaxHides]() As Nullable(Of System.Int32)
        Get
            Dim loValue As Object
            loValue = Me.CurrentRow.Item("INIMaxHides")
            If loValue Is DBNull.Value Then
                Return CType(Nothing, Nullable(Of System.Int32))
            Else
                Return New Nullable(Of System.Int32)(CType(loValue, System.Int32))
            End If
        End Get
    End Property

    ''' <summary>
    ''' INIMaxWeight
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("INIMaxWeight"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public ReadOnly Property [INIMaxWeight]() As Nullable(Of System.Int32)
        Get
            Dim loValue As Object
            loValue = Me.CurrentRow.Item("INIMaxWeight")
            If loValue Is DBNull.Value Then
                Return CType(Nothing, Nullable(Of System.Int32))
            Else
                Return New Nullable(Of System.Int32)(CType(loValue, System.Int32))
            End If
        End Get
    End Property

    ''' <summary>
    ''' INIMaxArea
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("INIMaxArea"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public ReadOnly Property [INIMaxArea]() As Nullable(Of System.Int32)
        Get
            Dim loValue As Object
            loValue = Me.CurrentRow.Item("INIMaxArea")
            If loValue Is DBNull.Value Then
                Return CType(Nothing, Nullable(Of System.Int32))
            Else
                Return New Nullable(Of System.Int32)(CType(loValue, System.Int32))
            End If
        End Get
    End Property


    Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()
        Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _
             New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor( _
            "OperatorName", GetType(boPUN_New)), _
             New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor( _
            "INIDescription", GetType(boPUN_New)), _
             New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor( _
            "INIMaxHides", GetType(boPUN_New)), _
             New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor( _
            "INIMaxWeight", GetType(boPUN_New)), _
             New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor( _
            "INIMaxArea", GetType(boPUN_New))}
    End Function

#End Region


 

By Trent L. Taylor - 12/14/2007

Peter,

There is not a "bug" in this particular instance otherwise none of the other fields would appear.  I did not look at your code in depth yet.  Standard mapped fields work on this very same principal and through the very same attributes, etc.  So if you setup your custom property correctly it will appear just like any other field....I will look at your code in more depth when I get a chance.  Just wanted to let you know that the standard properties work the very same as a custom property when setup correctly. Smile

By Greg McGuffey - 12/14/2007

Peter,



Your OperatorName property is actually called Product. Since your property descriptors are using OperatorName, this might be causing problems.
By Peter Jones - 12/14/2007

Hi Trent,

Thanks for the prompt feedback and information - I will await your further comments.

Greg - well spotted - a "copy and paste" typo I'm afraid but fixing it didn't change anything.

A comment I should have made in my original post is that in your sample code Trent the GetType funtion doesn't have a value, e.g.

             New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor( _
            "INIDescription", GetType(*** This is empty in the sample ***)), _

however, if I leave it empty in my code, I get an error in the IDE of "Type expected".

Cheers, Peter

By StrataFrame Team - 12/17/2007

Ah the fun with GetType...

"GetType" is both a keyword and a method of System.Object (at least it is in VB.NET... in C#, the keyword is typeof).  So, if you leave the value out of the parentheses in an instance method, the compiler is supposed to pick up on that fact and consider it to be Me.GetType() (which is the System.Object.GetType() call) which returns the type of the current object.  If you place a value in there, it's supposed to consider it to be the keyword call and pull the type that you placed in the parentheses.

But if the GetType is blue (the keyword color), then you know it's expecting the value to be placed in the parentheses like "GetType(MyBo)".  Otherwise, just put a Me. in front of it like this: Me.GetType() to force it to use the current object for the method call.

By Peter Jones - 12/17/2007

Hi Ben,

Great - Me.GetType() works fine although the GetType text in the original code was blue so I guess GetType(bo) should also have worked.

So, for the unwashed masses, is "Me.GetType()" the best approach when adding custom fields to a BO?

Cheers, Peter

By Trent L. Taylor - 12/18/2007

So, for the unwashed masses, is "Me.GetType()" the best approach when adding custom fields to a BO?

It is really a wash depending on the number of calls that you make.  The GetType(MyBoType) doesn't require an instance...however, in this case you are adding the type to the ReflectionPropertyDescriptors anyway so it will be an instance.

The only caution about calling Me.GetType() or GetType(MyBo) too many times is that tax that you take.  If you will be calling the GetType() very many times, you are better off passing this to a variable once then reusing that variable for the remaining calls:

Dim MyType As System.Type = Me.GetType()

'-- Use the MyType from this point on in this method to reduce the number of GetType calls.

By Peter Jones - 12/18/2007

Excellent, thanks Trent.

Cheers, Peter