[RESOLVED] Option strict implicit/disallow errors on a simple form
Hi, This is an only gif player form which does it once. (Sort of splash form)
Here's the code:
Code:
Public NotInheritable Class SplashScreen
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
CreateParams = MyBase.CreateParams
CreateParams.ExStyle = CreateParams.ExStyle Or &H2000000
Return CreateParams
End Get
End Property
Dim animatedImage = My.Resources.splash '*
Dim currentlyAnimating As Boolean = False
Dim framecounter As Integer = 0
Dim framecount As Integer
Dim framdim As Imaging.FrameDimension
Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
PictureBox1.Invalidate()
End Sub
Sub AnimateImage()
If Not currentlyAnimating Then
ImageAnimator.Animate(animatedImage, New EventHandler(AddressOf Me.OnFrameChanged)) '**
currentlyAnimating = True
End If
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If framecounter < framecount Then
AnimateImage()
ImageAnimator.UpdateFrames()
e.Graphics.DrawImage(Me.animatedImage, New Point(0, 0)) '***
framecounter += 1
Else
Me.Hide()
MainWindow.Show()
End If
End Sub
Private Sub SplashScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Opacity = 0
Me.Width = My.Resources.splash.Width
Me.Height = My.Resources.splash.Height
Me.TopMost = True
framdim = New Imaging.FrameDimension(animatedImage.FrameDimensionsList(0)) '****
framecount = animatedImage.GetFrameCount(framdim) '*****
End Sub
End Class
In option strict = off it works fine, no errors. In option strict = on, following errors will occur:
* Option Strict On requires all variable declarations to have an 'As' clause.
** Option Strict On disallows implicit conversions from 'Object' to 'Image'.
*** Overload resolution failed because no accessible 'DrawImage' can be called with these arguments: (A list of 'image' and 'object's.)
**** Option Strict On disallows late binding.
***** Option Strict On disallows late binding.
Re: Option strict implicit/disallow errors on a simple form
ALWAYS set Option Strict On at the project level. If you specifically need late binding then set it Off in the specific files where that's required. Even then, use partial classes to keep the code in those files to an absolute minimum.
The issue appears to be that you have Option Infer Off. This line is the root of the issue:
vb.net Code:
Dim animatedImage = My.Resources.splash
Whoever wrote that line was almost certainly assuming that the type of the animatedImage variable would be inferred from the type of the My.Resources.splash property, which requires Option Infer On. If it's On then the variable will have the same type as the property, which is presumably Image or Bitmap. With Option Infer Off, no type inference can occur, so you would need to either specify the type of the variable explicitly or else have it default to type Object. The latter will happen if you have Option Strict Off and don't specify the type but Option Strict On REQUIRES that you specify the type explicitly.
Basically, you need to decide whether you're going to set Option Infer On or Off. You don't need it On in most cases so you can turn it Off, but then you need to specify the type of every variable explicitly. I suggest that you set Option Infer On and use type inference where it's appropriate.
Re: Option strict implicit/disallow errors on a simple form
Thanks for clear information jmcilhinney.
The aforementioned error was rectified by adding 'as bitmap' to the line.