Option Strict On

R

Rob

I have employed a "Singleton mode" of programming for this project.

I have a class that exposes some properties of the class "Sample" to other
forms....

If I set Option Strict On, I get many "Option Strict On disallows late
binding" errors (see below)

How might I fix this ?


Public Class Sample

Private Shared DInstance As Sample = Nothing
Private Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub

Public Shared ReadOnly Property Instance()
Get
If (DInstance Is Nothing) Then DInstance = New Sample()
Return DInstance

End Get
End Property

Public Property TabControlAvailable() As TabControl
Get
Return Me.TabControl1

End Get
Set(ByVal value As TabControl)
Me.TabControl1 = value

End Set
End Property

Public Property SelectedTabAvailable() As TabPage
Get
Return Me.TabControl1.SelectedTab
End Get
Set(ByVal value As TabPage)
Me.TabControl1.SelectedTab = value
End Set
End Property


' These are the rows where the errors are pointing to...
Sample.Instance.Visible = True
Sample.Instance.TopMost = True
Sample.Instance.TabControlAvailable.SelectTab(strTabPageName)
Sample.Instance.Show()
 
R

rowe_newsgroups

I have employed a "Singleton mode" of programming for this project.

I have a class that exposes some properties of the class "Sample" to other
forms....

If I set Option Strict On, I get many "Option Strict On disallows late
binding" errors (see below)

How might I fix this ?

Public Class Sample

Private Shared DInstance As Sample = Nothing
Private Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub

Public Shared ReadOnly Property Instance()
Get
If (DInstance Is Nothing) Then DInstance = New Sample()
Return DInstance

End Get
End Property

Public Property TabControlAvailable() As TabControl
Get
Return Me.TabControl1

End Get
Set(ByVal value As TabControl)
Me.TabControl1 = value

End Set
End Property

Public Property SelectedTabAvailable() As TabPage
Get
Return Me.TabControl1.SelectedTab
End Get
Set(ByVal value As TabPage)
Me.TabControl1.SelectedTab = value
End Set
End Property

' These are the rows where the errors are pointing to...
Sample.Instance.Visible = True
Sample.Instance.TopMost = True
Sample.Instance.TabControlAvailable.SelectTab(strTabPageName)
Sample.Instance.Show()

Off hand the one major problem I see is that you don't have the
Instance shared property declared as a type. Add "As Sample" and see
if it clears up anything.

Thanks,

Seth Rowe
 
P

Phill W.

Rob said:
I have a class that exposes some properties of the class "Sample" to other
forms....

If I set Option Strict On, I get many "Option Strict On disallows late
binding" errors (see below)

/"If"/ you set it on???
IMHO, you should have this set it on /by default/ (under Tools >
Options) so that you always get told about this sort of thing.
Public Shared ReadOnly Property Instance() ???

I'd have expected the error to be something more like:

"Option Strict On requires all function and property declarations to
have an 'As' clause."

which (a) you're missing and (b) is far more explanatory, as error
messages go (in fairness, it's probably buried in amongst all the other
errors).

Add "As Sample" to your Property and you'll be fine.

HTH,
Phill W.
 
R

rowe_newsgroups

/"If"/ you set it on???
IMHO, you should have this set it on /by default/ (under Tools >
Options) so that you always get told about this sort of thing.


I'd have expected the error to be something more like:

"Option Strict On requires all function and property declarations to
have an 'As' clause."

which (a) you're missing and (b) is far more explanatory, as error
messages go (in fairness, it's probably buried in amongst all the other
errors).

Add "As Sample" to your Property and you'll be fine.

HTH,
Phill W.

"Option Strict On requires all function and property declarations to
have an 'As' clause."

As the OP didn't mention version, I wonder if this is just the VS 2005
message - perhaps 2003 warns of late binding on undeclared properties?

Thanks,

Seth Rowe
 
R

Rob

Regarding,

Yes, there was one of those, but when the "As type" was added it was
removed with the rest of the "late binding errors"

Thanks,
Rob
 
R

rowe_newsgroups

Regarding,


Yes, there was one of those, but when the "As type" was added it was
removed with the rest of the "late binding errors"

Thanks,
Rob







- Show quoted text -

I believe what Phill means is that errors are often cascading. The
root error was the "as type" problem, which caused the others. When
debugging it's important to not just focus on a certain error, but on
all the errors. If you would have posted all the error messages we
would have been able to solve the problem faster.

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top