p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   Passing info between assemblies & projects (http://p2p.wrox.com/showthread.php?t=16917)

BSkelding August 16th, 2004 09:41 AM

Passing info between assemblies & projects
Does anyone know how you can pass information between projects and/or assemblies? For instance, if I had a global variable in project 1 is there a way project 2 can look to see what it is set as? The same goes for assemblies.

planoie August 16th, 2004 12:05 PM

If I may clarify something: A project is not a run-time entity. All code in a project is compiled into an assembly. An assembly is just an assembly of classes, it doesn't really have a run-time context.

I would recommend you pass the information to methods of the assembly's classes. You can't have a global variable in an assembly (you can create constants within the namespace covered by an assembly, but of course, those are global variables). You can create global fields in a class and set those or pass the data into methods. Apart from the fact that it really can't be done, designing a system that relies on totally global variables is kind of bad. It will make things very hard down the road when you are trying to track down where one of those variables is getting set. I'd heavily recommend re-thinking your design.

BSkelding August 16th, 2004 12:23 PM

What I am really curious about doing is having projects that are in the same solution access the same object. For instance let's say I have a solution called Application. In the solution I have three projects, proj1,proj2,and proj3. I create an object in proj1 that has properties and methods. While coding proj2 is there anyway to access the object I created in proj1? Is passing it into proj2 an option? If so - how?

From your earlier post it sounds like it is not doable but I wanted to verify I understood correctly.

planoie August 16th, 2004 12:38 PM

The object has to live within some context. The "project" or even the application has no context. The first executing entity (such as a form or web page) has context. So an instance of an object could be global to a form and thus be accessible that way (by that and other forms). What you are explaining is too abstract.

If you are dealing with a single application (made of multiple projects) you could most certainly code functionality such that you can hand a class instance around when you call methods. This is done all the time starting with simple variables. What kind of projects make up your application? A single project can be a class library or an actual executable program so it would be a great help if you further explained what you are building, if indeed this is a practical discussion and not just a theoretical one.

BSkelding August 16th, 2004 01:26 PM

This would be one application. Most if not all the projects would be VB.NET projects, perhaps a few class libraries.

An example might be where project1 contains a form, frmMain, and a class called cClient. This project is the default startup project and runs upon clicking the EXE. You can click a button on frmMain that creates a new Client object, gClient, which is a global variable on frmMain.

I would then like the user to be able to navigate to a form, frmStats, that is created in project2 along with passing in gClient.

Does this help paint a clearer picture?

planoie August 16th, 2004 01:47 PM

Yes, that is a help. Thank you.

So you need to have these different applications talk to each other. I don't work with this type of scenario so I can't help you much more. What you are getting into sounds like dynamic data exchange (DDE) or whatever the .NET equivelant is. My work is primarily in ASP.NET applications so I'm not familiar with this type of programming.

Hopefully someone can join this thread and take over the discussion with more explanation of how you would acheive this in the .NET world.

katsarosj August 17th, 2004 12:11 AM

Is there a reason why you don't put everything in the same project?


BSkelding August 17th, 2004 07:40 AM

Right now it's just experimentation. In the future I think it would have more advantages in a team setting if one person preferred to code in say C#, the other in VB. Also, it may have some practical purposes if you were developing a modular type application.

Hal Levy August 17th, 2004 08:11 AM

This has no practical purpose in a well designed system. There is no problem, in a team setting, with objects copiled from different languages being in the same Solution. HOWEVER, a professional development team will establish standards and have everyone stick to them. What happens if the one person on your team that chose to use perl.NET leaves and now someone needs to maintain that code?

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee

katsarosj August 17th, 2004 08:42 AM

I agree with Hal. While you can work in multiple languages, most managers (at least the ones that I have worked with) will want to keep everything as uniform as possible.

If you want something for team development, you would be better off building classes that can be accessed by other members of the team but not changed.


All times are GMT -4. The time now is 02:03 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.