Re: How to pass information, classes between forms in Windows Application mode



On Jul 21, 1:34 pm, Jon Skeet [C# MVP] <sk...@xxxxxxxxx> wrote:
raylopez99 <raylope...@xxxxxxxxx> wrote:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms.

Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)

I still don't think it's your problem. You're still confused - and
what's more you've changed the problem from "accessing a variable" to
"information passing".

Nope. That was my problem. My problem was that I could not even see
the class1 in Form2 and now it's solved. Your problem (in your mind's
eye) is another problem altogether.


Certainly if you want to pass information from one context to a new
object, using a parameterised constructor is the way to go. That has
nothing to do with being able to access another type's variables
though.

Certainly.

And accessing another type's variables has nothing to do with my
problem, whether you acknowledge it or not. BTW, all my variables
were set public and still the code did not work until I hit upon the
parameterised constructor.


Just passing a parameter doesn't mean that Form2 is magically able to
see Form1.myClass1. Form2's constructor will be able to see the
parameter, which starts off with the same value as Form1.myClass1, but
you can't actually refer to the Form1.myClass1 variable from Form2.

You can too. Using the public properties Get and Set, you certainly
can refer to the Form1.myClass1 variables, even private variables, and
I demonstrated this in my code to my satisfaction. Would you like to
see a copy? Just open any textbook on C# and look under "Get" and
"Set" for Properties.

You remind me of the college professor who lost his keys in the dark,
and kept vainly looking under a street lamp far away from where he
lost them. When asked if he found the keys, he replied, "well, I
didn't lose my keys here, but this is the only place I know that has
light!" LOL, that's you Jon. You're answering a question that I didn't
pose (or perhaps I did pose, 'in your mind's eye'?).


The point being:  you need a forward reference if the Class1 is not
'nested' in the Form1 {}, that is, if Class1 is part of a separate
translation unit or module, even if Class1 is in the same namespace as
Form1.

No. There is no such thing as a forward reference in C#, and what you
seem to think is a forward reference is actually just a variable
declaration.

OK, let's call the forward declaration a 'variable declaration'. A
rose by any other name...

You're a funny dude. And you're wrong (but not 'in your mind's eye').

RL
.


Loading