Option Strict On lässt spätes binden nicht zu!

  • VB.NET

Es gibt 18 Antworten in diesem Thema. Der letzte Beitrag () ist von Jump3r.

    Option Strict On lässt spätes binden nicht zu!

    Erstmal einen schönen Abend allen :)
    Undzwar wollte ich mir einen sauberen Programmier-Stil angewöhnen und mit Option Strict on anfangen weshalb ich in meinem Browser nun auch unter Option Strict On programmieren wollte also hab ich Option Strict On angemacht und hatte viele Fehler die ich ALLE bis auf einen beheben konnte :

    VB.NET-Quellcode

    1. CType(Storm_Main.TabControl1.SelectedForm.Controls.Item(1), Skybound.Gecko.GeckoWebBrowser).Reload()

    Das ist ein fehler der mir sagt das spätes binden auf Grund von Option Strict On NICHT zugelassen wird und da ich eigentlich sauber(er) programmieren wollte wollte ich mal fragen ob sosnt noch wer eine Idee hat. BTW : Nutze das MDITabControl weshalb ich die Tabs nicht direkt via GeckoWebBrowser.Reload ansprechen kann da sonst immer nur die als erstes erstellte Tab-Seite angesprochen wird!


    Freue mich wie immer auf eure antworten :)
    Vielleicht so:

    VB.NET-Quellcode

    1. Dim GB As Skybound.Gecko.GeckoWebBrowser = CType(Storm_Main.TabControl1.SelectedForm.Controls.Item(1), Skybound.Gecko.GeckoWebBrowser)
    2. GB.Reload()
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Jetzt markiert er "Storm_Main.TabControl1.SelectedForm.Controls.Item(1)" und meckert wieder wegen dem späten binden :(


    EDIT :

    VB.NET-Quellcode

    1. Dim GB As Skybound.Gecko.GeckoWebBrowser = Skybound.Gecko.GeckoWebBrowser(CTYPE(Storm_Main.TabControl1.SelectedForm.Controls.Item(1))
    2. GB.Reload()


    Geht leider auch nicht :/
    Schreib mal

    VB.NET-Quellcode

    1. Dim Bla = Storm_Main.TabControl1.SelectedForm.Controls.Item(1)

    Halte die Maus Über Bla. Dann sollte ein Tooltip erscheinen, in dem "Dim Bla As ..." steht. Das was anstelle des ... steht postest Du mal hier. Ich vermute mal es ist Object.
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    Hm. Ich hab mir mal was angesehen.
    Setz mal einen Haltepunkt auf die von mir genannte Zeile und starte das Programm (und mach was, damit dieser Code ausgeführt wird).

    Dann hältst Du die Maus über Bla, klickst rechts, klickst auf Überwachung hinzufügen und guckst in der Liste was beim Eintrag Bla steht.

    Edit: Ein Screenshot vom expandierten Eintrag wäre schön^^
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    warte ich mach eben was dann lad ich pic hoch


    //EDIT :
    Spoiler anzeigen
    - TabControl1 {MdiTabControl.TabControl} MdiTabControl.TabControl

    VB.NET-Quellcode

    1. + AccessibilityObject {System.Windows.Forms.Control.ControlAccessibleObject} System.Windows.Forms.AccessibleObject
    2. AccessibleDefaultActionDescription Nothing String
    3. AccessibleDescription Nothing String
    4. AccessibleName Nothing String
    5. AccessibleRole Default {-1} System.Windows.Forms.AccessibleRole
    6. ActiveControl Nothing System.Windows.Forms.Control
    7. Alignment Top {0} MdiTabControl.TabControl.TabAlignment
    8. AllowDrop False Boolean
    9. AllowTabReorder True Boolean
    10. Anchor 5 System.Windows.Forms.AnchorStyles
    11. + AutoScaleDimensions {Width = 0.0 Height = 0.0} System.Drawing.SizeF
    12. AutoScaleMode None {0} System.Windows.Forms.AutoScaleMode
    13. AutoScroll False Boolean
    14. + AutoScrollMargin {Width = 0 Height = 0} System.Drawing.Size
    15. + AutoScrollMinSize {Width = 0 Height = 0} System.Drawing.Size
    16. + AutoScrollOffset {X = 0 Y = 0} System.Drawing.Point
    17. + AutoScrollPosition {X = 0 Y = 0} System.Drawing.Point
    18. AutoSize False Boolean
    19. AutoSizeMode GrowOnly {1} System.Windows.Forms.AutoSizeMode
    20. AutoValidate EnablePreventFocusChange {1} System.Windows.Forms.AutoValidate
    21. + BackColor "{Name=Control, ARGB=(255, 240, 240, 240)}" System.Drawing.Color
    22. BackgroundImage Nothing System.Drawing.Image
    23. BackgroundImageLayout Tile {1} System.Windows.Forms.ImageLayout
    24. + BackHighColor "{Name=Control, ARGB=(255, 240, 240, 240)}" System.Drawing.Color
    25. + BackLowColor "{Name=ControlLightLight, ARGB=(255, 255, 255, 255)}" System.Drawing.Color
    26. + BindingContext {System.Windows.Forms.BindingContext} System.Windows.Forms.BindingContext
    27. + BorderColor "{Name=ControlDarkDark, ARGB=(255, 105, 105, 105)}" System.Drawing.Color
    28. + BorderColorDisabled "{Name=ControlDark, ARGB=(255, 160, 160, 160)}" System.Drawing.Color
    29. BorderStyle None {0} System.Windows.Forms.BorderStyle
    30. Bottom 490 Integer
    31. + Bounds {X = 12 Y = 51 Width = 666 Height = 439} System.Drawing.Rectangle
    32. CanFocus True Boolean
    33. CanSelect True Boolean
    34. Capture False Boolean
    35. CausesValidation True Boolean
    36. CheckForIllegalCrossThreadCalls True Boolean
    37. + ClientRectangle {X = 0 Y = 0 Width = 666 Height = 439} System.Drawing.Rectangle
    38. + ClientSize {Width = 666 Height = 439} System.Drawing.Size
    39. CloseButtonVisible False Boolean
    40. CompanyName "Eduardo Oliveira" String
    41. Container Nothing System.ComponentModel.IContainer
    42. ContainsFocus False Boolean
    43. ContextMenu Nothing System.Windows.Forms.ContextMenu
    44. ContextMenuStrip Nothing System.Windows.Forms.ContextMenuStrip
    45. + ControlButtonBackHighColor "{Name=GradientInactiveCaption, ARGB=(255, 215, 228, 242)}" System.Drawing.Color
    46. + ControlButtonBackLowColor "{Name=GradientInactiveCaption, ARGB=(255, 215, 228, 242)}" System.Drawing.Color
    47. + ControlButtonBorderColor "{Name=HotTrack, ARGB=(255, 0, 102, 204)}" System.Drawing.Color
    48. + ControlButtonForeColor "{Name=ControlText, ARGB=(255, 0, 0, 0)}" System.Drawing.Color
    49. + Controls {System.Windows.Forms.Control.ControlCollection} System.Windows.Forms.Control.ControlCollection
    50. Created True Boolean
    51. + CurrentAutoScaleDimensions {Width = 0.0 Height = 0.0} System.Drawing.SizeF
    52. + Cursor {System.Windows.Forms.Cursor} System.Windows.Forms.Cursor
    53. + DataBindings {System.Windows.Forms.ControlBindingsCollection} System.Windows.Forms.ControlBindingsCollection
    54. + DefaultBackColor "{Name=Control, ARGB=(255, 240, 240, 240)}" System.Drawing.Color
    55. + DefaultFont {Name = "Microsoft Sans Serif" Size=8.25} System.Drawing.Font
    56. + DefaultForeColor "{Name=ControlText, ARGB=(255, 0, 0, 0)}" System.Drawing.Color
    57. + DisplayRectangle {X = 0 Y = 0 Width = 666 Height = 439} System.Drawing.Rectangle
    58. Disposing False Boolean
    59. Dock None {0} System.Windows.Forms.DockStyle
    60. + DockPadding {System.Windows.Forms.ScrollableControl.DockPaddingEdges} System.Windows.Forms.ScrollableControl.DockPaddingEdges
    61. DropButtonVisible True Boolean
    62. Enabled True Boolean
    63. Focused False Boolean
    64. + Font {Name = "Microsoft Sans Serif" Size=8.25} System.Drawing.Font
    65. FontBoldOnSelect True Boolean
    66. + ForeColor "{Name=ControlText, ARGB=(255, 0, 0, 0)}" System.Drawing.Color
    67. + ForeColorDisabled "{Name=ControlText, ARGB=(255, 0, 0, 0)}" System.Drawing.Color
    68. Handle 395386 System.IntPtr
    69. HasChildren True Boolean
    70. Height 439 Integer
    71. + HorizontalScroll {System.Windows.Forms.HScrollProperties} System.Windows.Forms.HScrollProperties
    72. HotTrack True Boolean
    73. ImeMode NoControl {0} System.Windows.Forms.ImeMode
    74. InvokeRequired False Boolean
    75. IsAccessible False Boolean
    76. IsDisposed False Boolean
    77. IsHandleCreated True Boolean
    78. IsMirrored False Boolean
    79. KeyCloseEnabled True Boolean
    80. KeyTabEnabled True Boolean
    81. + LayoutEngine {System.Windows.Forms.Layout.DefaultLayout} System.Windows.Forms.Layout.LayoutEngine
    82. Left 12 Integer
    83. + Location {X = 12 Y = 51} System.Drawing.Point
    84. + Margin {System.Windows.Forms.Padding} System.Windows.Forms.Padding
    85. + MaximumSize {Width = 0 Height = 0} System.Drawing.Size
    86. MenuRenderer Nothing System.Windows.Forms.ToolStripRenderer
    87. + MinimumSize {Width = 0 Height = 0} System.Drawing.Size
    88. ModifierKeys None {0} System.Windows.Forms.Keys
    89. MouseButtons None {0} System.Windows.Forms.MouseButtons
    90. + MousePosition {X = 436 Y = 492} System.Drawing.Point
    91. Name "TabControl1" String
    92. + Padding {System.Windows.Forms.Padding} System.Windows.Forms.Padding
    93. + Parent {VBP.Form1} System.Windows.Forms.Control
    94. + ParentForm {VBP.Form1} System.Windows.Forms.Form
    95. + PreferredSize {Width = 666 Height = 439} System.Drawing.Size
    96. ProductName "MdiTabControl" String
    97. ProductVersion "1.1.3159.34934" String
    98. RecreatingHandle False Boolean
    99. Region Nothing System.Drawing.Region
    100. RenderMode ManagerRenderMode {3} System.Windows.Forms.ToolStripRenderMode
    101. Right 678 Integer
    102. RightToLeft No {0} System.Windows.Forms.RightToLeft
    103. + SelectedForm {VBP.Form2} Object
    104. Site Nothing System.ComponentModel.ISite
    105. + Size {Width = 666 Height = 439} System.Drawing.Size
    106. SmoothingMode None {3} System.Drawing.Drawing2D.SmoothingMode
    107. + TabBackHighColor "{Name=Window, ARGB=(255, 255, 255, 255)}" System.Drawing.Color
    108. + TabBackHighColorDisabled "{Name=Control, ARGB=(255, 240, 240, 240)}" System.Drawing.Color
    109. + TabBackLowColor "{Name=Control, ARGB=(255, 240, 240, 240)}" System.Drawing.Color
    110. + TabBackLowColorDisabled "{Name=ControlDark, ARGB=(255, 160, 160, 160)}" System.Drawing.Color
    111. TabBorderEnhanced False Boolean
    112. TabBorderEnhanceWeight Medium {3} MdiTabControl.TabControl.Weight
    113. + TabCloseButtonBackHighColor "{Name=IndianRed, ARGB=(255, 205, 92, 92)}" System.Drawing.Color
    114. + TabCloseButtonBackHighColorDisabled "{Name=LightGray, ARGB=(255, 211, 211, 211)}" System.Drawing.Color
    115. + TabCloseButtonBackHighColorHot "{Name=LightCoral, ARGB=(255, 240, 128, 128)}" System.Drawing.Color
    116. + TabCloseButtonBackLowColor "{Name=Firebrick, ARGB=(255, 178, 34, 34)}" System.Drawing.Color
    117. + TabCloseButtonBackLowColorDisabled "{Name=DarkGray, ARGB=(255, 169, 169, 169)}" System.Drawing.Color
    118. + TabCloseButtonBackLowColorHot "{Name=IndianRed, ARGB=(255, 205, 92, 92)}" System.Drawing.Color
    119. + TabCloseButtonBorderColor "{Name=DarkRed, ARGB=(255, 139, 0, 0)}" System.Drawing.Color
    120. + TabCloseButtonBorderColorDisabled "{Name=Gray, ARGB=(255, 128, 128, 128)}" System.Drawing.Color
    121. + TabCloseButtonBorderColorHot "{Name=Firebrick, ARGB=(255, 178, 34, 34)}" System.Drawing.Color
    122. + TabCloseButtonForeColor "{Name=White, ARGB=(255, 255, 255, 255)}" System.Drawing.Color
    123. + TabCloseButtonForeColorDisabled "{Name=White, ARGB=(255, 255, 255, 255)}" System.Drawing.Color
    124. + TabCloseButtonForeColorHot "{Name=White, ARGB=(255, 255, 255, 255)}" System.Drawing.Color
    125. TabCloseButtonImage Nothing System.Drawing.Image
    126. TabCloseButtonImageDisabled Nothing System.Drawing.Image
    127. TabCloseButtonImageHot Nothing System.Drawing.Image
    128. + TabCloseButtonSize {Width = 17 Height = 17} System.Drawing.Size
    129. TabCloseButtonVisible True Boolean
    130. TabGlassGradient False Boolean
    131. TabHeight 28 Integer
    132. + TabIconSize {Width = 16 Height = 16} System.Drawing.Size
    133. TabIndex 2 Integer
    134. TabMaximumWidth 200 Integer
    135. TabMinimumWidth 100 Integer
    136. TabOffset 3 Integer
    137. TabPadLeft 5 Integer
    138. TabPadRight 5 Integer
    139. + TabPages {MdiTabControl.TabControl.TabPageCollection} MdiTabControl.TabControl.TabPageCollection
    140. TabsDirection LeftToRight {0} MdiTabControl.TabControl.FlowDirection
    141. TabStop True Boolean
    142. TabTop 3 Integer
    143. Tag Nothing Object
    144. Text "" String
    145. Top 51 Integer
    146. + TopLevelControl {VBP.Form1} System.Windows.Forms.Control
    147. TopSeparator True Boolean
    148. UseWaitCursor False Boolean
    149. + VerticalScroll {System.Windows.Forms.VScrollProperties} System.Windows.Forms.VScrollProperties
    150. Visible True Boolean
    151. Width 666 Integer
    152. + WindowTarget {System.Windows.Forms.Control.ControlNativeWindow} System.Windows.Forms.IWindowTarget



    //EDIT 2:
    So zeigt er zwar keinen Fehler wegen binden an :

    VB.NET-Quellcode

    1. CType(TabControl1.TabPages.SelectedTab.Controls.Item(1), Skybound.Gecko.GeckoWebBrowser).Reload()

    Dafür sagt er aber das der Index ausserhalb des bereichs liegt obwohk item 1 der GeckoBrowser ist!

    //EDIT 3 :
    Leider auch nicht dann sagt er das der Objektverweis nicht auf eine Objektinstanz festglegt wurde :

    VB.NET-Quellcode

    1. CType(TabControl1.TabPages.SelectedTab.Controls("GeckoWebBrowser1".ToString), Skybound.Gecko.GeckoWebBrowser).Reload()

    Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „Jump3r“ ()

    Ach. Jetzt weiß ich schon woran es liegt.
    Sieh Dir mal Zeile 103 an. Was steht da?
    Name: SelectedForm. Wert: {VBP.Form2} (ist also eine Instanz von VBP.Form2). und Typ?
    Object

    Das Problem liegt also bei Storm_Main.TabControl1.SelectedForm.Controls

    Denn: SelectedForm ist vom Typ Object. Und da gibt es keinen Member "Controls".
    Es kann durchaus sein, dass später dieses Object dann auf eine Instanz eines Typs mit einem Member "Controls" zeigt, aber zum Zeitpunkt des Kompilierens steht das noch nicht fest. Darum "Spätes Binden".

    Hier musst Du folgendes machen:
    Anstelle von Storm_Main.TabControl1.SelectedForm.Controls.Item(1)
    schreibst Du

    VB.NET-Quellcode

    1. DirectCast(Storm_Main.TabControl1.SelectedForm, VBP.Form2).Controls.Item(1)


    Dann kannst Du in den WebBrowser casten und dann kanst Du reloaden.

    VB.NET-Quellcode

    1. DirectCast(DirectCast(Storm_Main.TabControl1.SelectedForm, VBP.Form2).Controls.Item(1), Skybound.Gecko.GeckoWebBrowser).Reload()



    Das mit VBP.Form2 musst Du Dir noch überlegen. Falls da nicht immer eine VBP.Form2 drin ist, sondern auch mal eine VBP.Form1, musst Du in den übergeordneten Typ casten. Ich denke mal, dass VBP Form2 von System.Windows.Forms.Form erbt. Darum kannst Du DirectCast(..., Form) schreiben (vermutlich).
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils

    VB.NET-Quellcode

    1. DirectCast(DirectCast(TabControl1.SelectedForm, VBP.Form2).Controls.Item(0), Skybound.Gecko.GeckoWebBrowser).Reload()


    So gehts 1A, danke bist super und vorallem hast du mir den Abend gerettet hab zwar auch bisn was versucht aber der Dank gehört alleine dir :) :thumbup:

    Wieso kann ich pro post nur 1 mal danken? XD
    Ach. Vielen Dank. ^^

    Edit: Was ich noch anhängen möchte:
    Das mit dem doppelt Casten ist extrem unübersichtlich. Vielleicht findest Du noch eine andere Möglichkeit auf den WebBrowser zuzugreifen. Z.B. ihn in eine Variable zu packen und dann auf diese zuzugreifen. Dann musst Du überhaupt nur noch Variablenname.Reload() schreiben. Aber Du hast schon im ersten Post geschrieben, dass das nicht richtig funktioniert.

    Vielleicht findest Du noch was.
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    Eigentlich ist DirectCast sogar ein extrem schneller Befehl.
    Aber Die Syntax

    VB.NET-Quellcode

    1. DirectCast(DirectCast(Eine.Extrem.Lange.Reihe.Von.Ausdrücken, Typ1).Und.Noch.Ein.Haufen.Member, Typ2).DoSomething()


    ist sehr schwer durchschaubar.

    Schön wäre eine Extension-Function.

    VB.NET-Quellcode

    1. Eine.Extrem.Lange.Reihe.Von.Ausdrücken.CastTo(Typ1).Und.Noch.Ein.Haufen.Member.CastTo(Typ2).DoSomething()


    Denn da kann man von links nach rechts durchlesen, ohne nochmal zurückzugehen "Was wird jetzt noch mal damit gemacht?".
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    Ah super,
    eien frage noch (ich hoffe keiner ist dann böse) dann haste auch ruhe undzwar bekomme ich bei

    VB.NET-Quellcode

    1. If Not TabControl1.SelectedForm.Text = "Verarbeite Daten..." Then
    2. Me.Text = TabControl1.SelectedForm.Text & " - Storm"
    3. End if


    Wieder den selber Error und naja :rolleyes: ich pack dich auch ins Info-Fenster :)


    //EDIT :
    Habs

    VB.NET-Quellcode

    1. If Not TabControl1.TabPages.SelectedTab.Text = "Verarbeite Daten..." Then
    2. Me.Text = DirectCast(DirectCast(TabControl1.SelectedForm, Browser).Controls.Item(0), Skybound.Gecko.GeckoWebBrowser).DocumentTitle & " - Storm"
    3. Else


    Bist trotzdem im Infofenster ;)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Jump3r“ ()

    Danke für die Erwähnung. Wäre aber nicht nötig.
    Und um das Problem mit der Syntax zu unterstrichen:
    Ich hab jetzt so gelesen:

    Mein Gehirn schrieb:


    Hmm.... TabControl1.SelectedForm. Das war doch das Object.
    Beistrich Browser? *Links Scroll* Achso. DirectCast. *Rechts Scroll* Aber was ist Browser für ein Typ?
    Dann .Controls.Item(0), also das erste Control.
    Beistrich. Schon wieder DirectCast? *Links Scroll* DirectCast. Das war von vorhin. *Weiter Links Scroll* Ach so. Ja. *Rechts Scroll* Zu dem GeckoBrowser.
    .DocumentTitle Und - Strom.
    Achso. Ok.


    Man sieht: Ich musste mehrmals nach links gucken und dann wieder nach rechts. Ist halt etwas umständlich, aber z.Z. im Framework nicht anders realisiert.


    Und nochwas: Das erste Element einer Auflistung / eines Arrays bekommt man mit .First (und das letzte mit .last), falls Du .Net Framework 3.5 oder höher verwendest.
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils