adam_pedley
asked on
Convert a form to a type
Hi
I have a form which implements an interface.
I then get this form via an object with its type lost.
So I want to convert it back to a form that implements that interface.
How do I do that?
Thanks
Adam
I have a form which implements an interface.
I then get this form via an object with its type lost.
So I want to convert it back to a form that implements that interface.
How do I do that?
Thanks
Adam
ASKER
Public Class SomeForm
inherits windows.forms.form
implements ISomeInterface
End Class
I cant set the object as a the type of interface as then i lose all the form functions etc
inherits windows.forms.form
implements ISomeInterface
End Class
I cant set the object as a the type of interface as then i lose all the form functions etc
Some thoughts...
(1) pass it as Object...then convert to Form or ISomeInterface as necessary
(2) include what you need from the Form as part of the Interface...isn't that what they are for?...to give common functionality?
Or give us more context of what you are doing...perhaps a different approach may be in order.
(1) pass it as Object...then convert to Form or ISomeInterface as necessary
(2) include what you need from the Form as part of the Interface...isn't that what they are for?...to give common functionality?
Or give us more context of what you are doing...perhaps a different approach may be in order.
ASKER
Ok i have a number of forms that each have the same set of specific functions
So each form implements the ISomeInterface.
I then use reflection to get these forms as they are not in the current application but a DLL.
Then if I CType(someForm, Form)
I lose all the functions that are implemented via the interface.
If i CType(someForm, ISomeInterface) I lose all of the form functionality such as .invoke .show etc
So i need to convert it to a type that includes the function list from both or need to declare the forms in the other DLL differently first. But im not sure how to do this.
So each form implements the ISomeInterface.
I then use reflection to get these forms as they are not in the current application but a DLL.
Then if I CType(someForm, Form)
I lose all the functions that are implemented via the interface.
If i CType(someForm, ISomeInterface) I lose all of the form functionality such as .invoke .show etc
So i need to convert it to a type that includes the function list from both or need to declare the forms in the other DLL differently first. But im not sure how to do this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Genius once again idle_mind
Lol...I wouldn't say that was Genius...sometimes you just need an external viewpoint to see things differently. =)
ASKER
I believe your ranking speaks for itself :)
VB.NET Certified Expert
Genius Level
VB.NET Certified Expert
Genius Level
If TypeOf someObject Is yourInterfaceName Then
Dim someVar As yourInterfaceName = CType(someObject, yourInterfaceName)
' do something with someVar...
End If