By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Initialization order

P: n/a
Dear all,
what is initialization order of members in VB?
Sometimes following assertion fails. Why?
Thank you in advance,
Boni
class A
inherits class B
dim pen as new system.drawing.pen(.)
sub new(.)
mybase.new(.)
debug.assert(not pen is nothing,"ops")
end sub
end class
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
first the base class then the constructor , and then the members
so safest is to do this
sub new(.)
mybase.new(.)
dim pen as new system.drawing.pen(.)
debug.assert(not pen is nothing,"ops")
end sub
or

private pen as system.drawing.pen()
sub new(.)
mybase.new(.)
pen = new system.drawing.pen()
debug.assert(not pen is nothing,"ops")
end sub
ofcourse there are more possibility`s depending on your situation

michel posseth
"Boni" wrote:
Dear all,
what is initialization order of members in VB?
Sometimes following assertion fails. Why?
Thank you in advance,
Boni
class A
inherits class B
dim pen as new system.drawing.pen(.)
sub new(.)
mybase.new(.)
debug.assert(not pen is nothing,"ops")
end sub
end class

Nov 21 '05 #2

P: n/a
Hi,
I have a strange situation. I have a class with many constructors,
and a private member pen=new pen.
The call to draw function happens, when constructors is completely
finished.
But pen is nothing. If I initialize pen in constructor it does not happen.
Any ideas?
Thank you very much for your help.

"M. Posseth" <MP******@discussions.microsoft.com> schrieb im Newsbeitrag
news:D2**********************************@microsof t.com...
first the base class then the constructor , and then the members
so safest is to do this
sub new(.)
mybase.new(.)
dim pen as new system.drawing.pen(.)
debug.assert(not pen is nothing,"ops")
end sub
or

private pen as system.drawing.pen()
sub new(.)
mybase.new(.)
pen = new system.drawing.pen()
debug.assert(not pen is nothing,"ops")
end sub
ofcourse there are more possibility`s depending on your situation

michel posseth
"Boni" wrote:
Dear all,
what is initialization order of members in VB?
Sometimes following assertion fails. Why?
Thank you in advance,
Boni
class A
inherits class B
dim pen as new system.drawing.pen(.)
sub new(.)
mybase.new(.)
debug.assert(not pen is nothing,"ops")
end sub
end class

Nov 21 '05 #3

P: n/a
More code..

Friend Class A

Inherits B

Private m_pen As New System.Drawing.Pen(System.Drawing.Color.Beige) 'color
is dummy ! It is changed it time

Public Overrides Sub Draw()

Debug.Assert(Not Me.m_pen Is Nothing, "pen is nothing")

If Me.m_pen Is Nothing Then

Me.m_pen = New System.Drawing.Pen(System.Drawing.Color.Beige)

End If

End Sub

Public Sub New(ByVal id As intgere)

MyBase.New("aaaaa",id)

End Sub

Public Sub New()

MyBase.New()

End Sub

End Class
Nov 21 '05 #4

P: n/a
I am just decompiled the dll and now I am really confused. m_pen is created
not in all constructors!!!
I thought that if I initialize class member on the way like I did with pen,
it is declared in all constructors.
Please could somebody elaborate on this?
Public Sub New(....)

MyBase.New(..)

Return

End Sub

Public Sub New()

MyBase.New()

_m_pen = New Pen(Color.Beige)

Return

End Sub
"Boni" <oilia@nospam> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl...
More code..

Friend Class A

Inherits B

Private m_pen As New System.Drawing.Pen(System.Drawing.Color.Beige) 'color
is dummy ! It is changed it time

Public Overrides Sub Draw()

Debug.Assert(Not Me.m_pen Is Nothing, "pen is nothing")

If Me.m_pen Is Nothing Then

Me.m_pen = New System.Drawing.Pen(System.Drawing.Color.Beige)

End If

End Sub

Public Sub New(ByVal id As intgere)

MyBase.New("aaaaa",id)

End Sub

Public Sub New()

MyBase.New()

End Sub

End Class

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.