1 Attachment(s)
Same UserControl/Form in 2 different Projects
Let's see the attached zip if you don't understand... the example will clarify itself.
I have two different projects: "Project1" and "Project2". Both projects have a form which uses an UserControl. Both, the Form and the UserControl are common for both projects. If you open project1.vbp and/or project2.vbp you see'll what I mean.
However, if you open the project2.vbp you'll realize that VB raises an error: "Class Project1.UserControl1 of control UserControl11 was not a loaded control class."
The explanation is pretty simple. Form1 has a reference to load the control Project1.UserControl1... but this project's name is Project2, so the usercontrol cannot be found. If I edited the Form1 to load the control Project2.UserControl2, this project2 would start "loading" correctly... but Project1 would start raising a similar error.
Is there any way to fix this?
Re: Same UserControl/Form in 2 different Projects
have you tried making a project group with both projects included in it
rgds pete
Re: Same UserControl/Form in 2 different Projects
A project group is definitely the answer. You also need to create the User Control as a separate project in the group as an ActiveX control.
Re: Same UserControl/Form in 2 different Projects
I don't think a project group could be the answer. The Usercontrol MUST be part of the project because I will not distribute the Usercontrol as an OCX but as part of the compiled code. If the UserControl and the rest of the code were in two different projects I'll need to compile the Usercontrol and distribute the OCX as well.
Re: Same UserControl/Form in 2 different Projects
Quote:
Originally Posted by Mc Brain
I don't think a project group could be the answer. The Usercontrol MUST be part of the project because I will not distribute the Usercontrol as an OCX but as part of the compiled code. If the UserControl and the rest of the code were in two different projects I'll need to compile the Usercontrol and distribute the OCX as well.
Project Group is definitely the answer (well, vbg isn't necessary but certainly better way to control all shared files) - all you have to do is to add that user control to your second project: right click on project explorer and select add -> file ... and point to your UserControl1.ctl. That's all - from now on both projects will share one user control.
It's a little inconvenient - every time you make changes in one project you'll have to confirm changes for all the rest of your projects sharing the same object (form, class, module, user control, etc) but other than that you'll benefit by having less objects over all.
Regards.
Re: Same UserControl/Form in 2 different Projects
I think I'm not following. Can you post an example (as I did), please?
Re: Same UserControl/Form in 2 different Projects
Quote:
Originally Posted by Mc Brain
Let's see the attached zip if you don't understand... the example will clarify itself.
I have two different projects: "Project1" and "Project2". Both projects have a form which uses an UserControl. Both, the Form and the UserControl are common for both projects. If you open project1.vbp and/or project2.vbp you see'll what I mean.
However, if you open the project2.vbp you'll realize that VB raises an error: "Class Project1.UserControl1 of control UserControl11 was not a loaded control class."
The explanation is pretty simple. Form1 has a reference to load the control Project1.UserControl1... but this project's name is Project2, so the usercontrol cannot be found. If I edited the Form1 to load the control Project2.UserControl2, this project2 would start "loading" correctly... but Project1 would start raising a similar error.
Is there any way to fix this?
Yes. You can take the usercontrol out of both projects, and make it part of its own project. Then compile the usercontrol into its own .OCX file, and make it Binary Compatible. That way, the GUID will always stay the same and both projects can load the user control correctly.
The downside to this, is you won't be able to step through the code of the usercontrol (usually this isn't a big problem).
Does that help, or do you need more info?