Re: How to pass information, classes between forms in Windows Application mode
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Tue, 22 Jul 2008 13:12:15 +0100
raylopez99 <raylopez99@xxxxxxxxx> wrote:
And accessing another type's variables has nothing to do with my
problem, whether you acknowledge it or not.
It has everything to do with the problem you originally described,
which had one form inheriting from another. However, when you came to
show actually code your forms were both inheriting from Form.
BTW, all my variables
were set public and still the code did not work until I hit upon the
parameterised constructor.
Indeed, because your code wasn't how you originally described it. You
claimed an inheritance relationship which simply wasn't there.
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.
That's not referring to the variables. That's referring to the
properties, which happen to the return the current variable value. Big
difference. Try passing the property by reference, for example...
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'?).
No, I'm answering the question you *did* pose, even though it may not
have reflected reality. You repeatedly stated that the child form
inherited from the parent form - but then your code showed otherwise.
That's what confused me - I foolishly trusted that you were accurately
describing your code.
So yes, I'll take part of the blame for not solving your problem
earlier - but you should also accept your portion of it for
misdescribing it in the first place.
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...
Um, no. A forward declaration in C++ is not the same thing as a
variable declaration at all.
You're a funny dude. And you're wrong (but not 'in your mind's eye').
Fine, you believe that. Just don't expect people to keep trying to help
you when you refuse to use correct terminology, misdescribe your
situation, and then claim to know better than they do despite making
wild claims about how the language works. I enjoy teaching and
coaching, which is why I participate here - but it's got to be a two-
way process.
--
Jon Skeet - <skeet@xxxxxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
.
- Follow-Ups:
- References:
- How to pass information, classes between forms in Windows Application mode
- From: raylopez99
- Re: How to pass information, classes between forms in Windows Application mode
- From: Jon Skeet [C# MVP]
- Re: How to pass information, classes between forms in Windows Application mode
- From: raylopez99
- How to pass information, classes between forms in Windows Application mode
- Prev by Date: Re: What classes are suitable for working with XML?
- Next by Date: Drop a link to Outlook message
- Previous by thread: Re: How to pass information, classes between forms in Windows Application mode
- Next by thread: Re: How to pass information, classes between forms in Windows Application mode
- Index(es):
Relevant Pages
|