Link to home
Start Free TrialLog in
Avatar of adam_pedley
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
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

This seems to easy...what am I missing?

    If TypeOf someObject Is yourInterfaceName Then
        Dim someVar As yourInterfaceName = CType(someObject, yourInterfaceName)
        ' do something with someVar...
    End If
Avatar of adam_pedley
adam_pedley

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
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.
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.

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Genius once again idle_mind

Lol...I wouldn't say that was Genius...sometimes you just need an external viewpoint to see things differently.  =)
I believe your ranking speaks for itself :)

VB.NET Certified Expert
Genius Level