apologies for my probably naive question here but I'm stuck on an issue I seem to be coming up against.
Currently...
I have a class, that inherits a 'Button' control (specifically the Button of the Guna framework (nuget)),
this class gets passed to an array and then to a Scriptcontrol class and added to a VBscript (courtesy of .AddObject)
For the script control to see the objects I seem to need to have Comvisible set as true- I have set this in the assembly info. and tried declaring it in each class.
I can add the objects to the script ok, however, the problem occurs when I try to do anything with the object in the script. The script says "operation is not legal in the current state" It seems to point to ComVisible being false in dependant classes or objects. - but I could be wrong, I probably am.
If I remove the inherited framework, and inherit a standard VS control (i.e. Button), then the script works as it should, and I can access objects in the script.
Am I able to inherit a control and override its Comvisible attribute / force it? Is there a better way of doing that? or, am I probably adding the objects to the script wrong?
I am using VS2019 - vb - winforms -.net4.8
Thanks, in advance.
Imports System.Runtime.InteropServices
<ComVisible(True)>
Public Class Form1
Public ObjectArray(10) As MyButton
Dim SCRIPT1 As New ScriptController
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Init()
End Sub
Sub Init()
Dim i As Integer
For i = 0 To 9
ObjectArray(i) = New MyButton
ObjectArray(i).Property1 = i.ToString
Next i
SCRIPT1.DoScript(ObjectArray)
End Sub
End Class
Public Class ScriptController
Inherits MSScriptControl.ScriptControlClass
Dim c As New Collection
Public ScriptToRun As String = (" Sub Main () " & vbCrLf &
" " & vbCrLf &
" Objects1(2).Property1 = ""Howdy"" " & vbCrLf &
" msgbox Objects1(2).Property1 " & vbCrLf &
" " & vbCrLf &
"End Sub")
Public Sub DoScript(ObjArr() As Object)
Dim s As New MSScriptControl.ScriptControlClass
Dim i As Integer
c.Clear()
For i = 1 To 10
c.Add(ObjArr(i - 1))
Next i
s.Language = "vbscript"
s.AllowUI = True
s.AddObject("Objects1", c, True)
s.AddCode(ScriptToRun)
s.Run("Main")
s.Reset()
End Sub
End Class
Public Class MyButton
' Inherits Guna.UI2.WinForms.Guna2Button
' // Changing between these switches the problem //
Inherits Button
Public Property Property1 As String
End Class