cross-project variable access within the same solution

  • Thread starter Thread starter Chris Voon
  • Start date Start date
C

Chris Voon

Hi all,

I've a solution containing 2 projects, one for the GUI
whereas the other contains the data logic. On the GUI, I
have some controls to capture user's input. User will
initiate some action by clicking say a button on the GUI.
It will then invoke the data logic and the data logic
project will try to retrieve some user input from the GUI.
When it was in VB, it's simply done by accessing each
control component directly. But now in VB.net everything
is an object. So i will need a reference of this GUI form
and go further from there to obtain values within those
components within the form. I am aware that it's possible
to pass variable from the form to the data logic classes,
but i wish to do it such a way that i simply call a
function within the data logic without passing any
variable and the data logic class access the GUI's
components and then their values therein.

Thanks once again for those smart ppl that helps me to
figure this out.
 
but i wish to do it such a way that i simply call a
function within the data logic without passing any
variable and the data logic class access the GUI's
components and then their values therein.


Just pass a reference of the GUI to the constructor of the data logic. Be
aware, that the components of the GUI must have at least 'Friend'-access.

D.Barisch
 
Thanks for the reply.
I believe this wont work for me as the data logic is in
another project, which "friend" is meant for within the
same namespace/project. However, this inspire me of the
idea to change all the variable to public.

However, this wont solve the problem. Consider this
situation. I have 2 projects, one with GUI and one with
data logic.

The GUI's assembly is in exe while the data logic is dll.
I will need a reference of the GUI project in the data
logic project. However this is not allowed because it's an
EXE. Hence no reference allowed.
 
You're basically trying to do cross-process communication. You'll have to
send a windows message with the data, write to a shared memory area or file,
use the registry, use a database, send an event or something along those
lines.

-Chris
 
The GUI's assembly is in exe while the data logic is dll.
I will need a reference of the GUI project in the data
logic project. However this is not allowed because it's an
EXE. Hence no reference allowed.

Maybe it sounds strange, but maybe it works: turn around the projects.
Compile the data-logic into an exe and define the forms you need to show
within a library.

D.Barisch
 
Thank you all.

I've resolved this problem by creating everything within
the same project and they just link without any problem.
Think i've made a rather major poor decision to partition
my functionality of one single application within several
projects. Since I have control over all the code, hence it
will be easier to reference any class, structure or enum
that i created. Besides, it also deploys much faster! I
used to wait a minute for each debug with 5 projects under
my solution space. After all maybe i should put them under
different namespace rather than different projects.
Perhaps that will aid in logically group them.

Regards,
Chris
 
Back
Top