Stoopid Q

S

Sueffel

And here I thought I had a handle on things. Well, maybe not. Here's
my scenerio, I have a form I need to reuse, so I thought, let's throw the
sucker in a DLL. Well, running into a problem, I can't seem to cast my
form, Form1, as a form. Kinda strange. Here's the Function in the DLL:

Public Function ReturnForm as Form
Dim frm As Form
frm=New Form1
Return frm
End Function

I put it in a class within the app, and same thing... I'm starting to think
that I have to create the form from within the function all by hand, boy
that would suck. So, my question is, why is this cast invalid?

Thanks,
Sueffel
 
A

Armin Zingler

Sueffel said:
And here I thought I had a handle on things. Well, maybe not.
Here's
my scenerio, I have a form I need to reuse, so I thought, let's throw
the sucker in a DLL. Well, running into a problem, I can't seem to
cast my form, Form1, as a form. Kinda strange. Here's the Function
in the DLL:

Public Function ReturnForm as Form
Dim frm As Form
frm=New Form1
Return frm
End Function

I put it in a class within the app, and same thing... I'm starting
to think that I have to create the form from within the function all
by hand, boy that would suck. So, my question is, why is this cast
invalid?

The function works here. I'd change the return type to "As Form1" because
only this type of Form will be returned. You could also make the function
shorter:

Public Function ReturnForm as Form
Return New Form1
End Function

....or you can get rid of it:

<code>
</code>


Instead of calling the function "bla = ReturnForm", simply write "bla = New
Form1".


But, I guess I didn't understand the "casting" problem you were talking
about. Could you please explain?
 
H

Herfried K. Wagner [MVP]

* "Sueffel said:
And here I thought I had a handle on things. Well, maybe not. Here's
my scenerio, I have a form I need to reuse, so I thought, let's throw the
sucker in a DLL. Well, running into a problem, I can't seem to cast my
form, Form1, as a form. Kinda strange. Here's the Function in the DLL:

Public Function ReturnForm as Form
Dim frm As Form
frm=New Form1
Return frm
End Function

I put it in a class within the app, and same thing... I'm starting to think
that I have to create the form from within the function all by hand, boy
that would suck. So, my question is, why is this cast invalid?

Are you sure 'Form1' inherits from 'Form'? Do you define a 2nd 'Form'
class inside your DLL?
 
S

Sueffel

Sueffel said:
And here I thought I had a handle on things. Well, maybe not. Here's
my scenerio, I have a form I need to reuse, so I thought, let's throw the
sucker in a DLL. Well, running into a problem, I can't seem to cast my
form, Form1, as a form. Kinda strange. Here's the Function in the DLL:

Public Function ReturnForm as Form
Dim frm As Form
frm=New Form1
Return frm
End Function

I put it in a class within the app, and same thing... I'm starting to think
that I have to create the form from within the function all by hand, boy
that would suck. So, my question is, why is this cast invalid?

Thanks,
Sueffel
I did try changing the return type to Form1, and I got an an unspecified
error in the main app. And I did verify that it inherited
System.Windows.Forms.Form. I did try something else though, I made a new
form class via the designer, and put my command function into the form
itself as such:

Public Function Command() As Form

Return Me

End Function

Since it's already run through it's init stuff, this works great.

This works just fine, even using it to call other objects from within the
DLL itself and passing that through. So I now have the ability to use my
LateBound DLL's as plugins and not only include my forms, but all code as a
code-behind type of scenerio. The only question that remains is with the
late-binding itself. After I destroy the object, it still seems to remain
active in memory somewhere, while this isn't critical, it's annoying because
I wanted to be able to copy right over that DLL with a new one if necesarry.
Someone mentioned using Side-by-side versioning, allowing 2 versions to
co-exist and all that jazz, but that's way more than what I need, and all
that stuff. It looks like I've got a very viable solution as it stands, so
I'm going to run with that on this project. Now, to solve my graphics
problem with my proxy server! LOL

Thanks again everyone,
Sueffel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top