By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,279 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,279 IT Pros & Developers. It's quick & easy.

'Friend' vs. 'Protected Friend'

P: n/a
Friend variables "are accessible from within the program that contains their
declaration and from anywhere else in the same assembly." according to the
VS.Net help. This sounds like a pretty broad scope!

So why, when attempting to inherit a form from a base form class, is
'Friend' inadequate to give inherited forms 'public'-style access to
inherited controls? I.E. - i have a base form with two group boxes on it.
When they are declared 'Friend', i can't drag and drop controls into them in
inherited forms in the visual form designer. When they are declared
'Protected Friend', they work as expected.

Getting back to the definition of Friend - isn't any inherited form within
the same project going to be considered "...within the program... [or] ...in
the same assembly."? By now, my empirical evidence indicates that this not
the case, but i am wondering WHY?!

TIA! =)
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sometimes declaring something as Friend is illegal as it exposes a public
object.

Example:

Friend Enum Foo
Alpha
Beta
Gamma
End Enum

Public Class Bar
Public Sub Baz(ByVal Moo As Foo)
'
End Sub
End Class

Baz has Moo declared as Foo for it's parameter. Foo is a friend type, and
Bar is a public class. It is invalid because A public type cannot expose a
friend type.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"K. Shier" <ks*****@spamAtYourOwnRisk.yahoo.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
: Friend variables "are accessible from within the program that contains
their
: declaration and from anywhere else in the same assembly." according to the
: VS.Net help. This sounds like a pretty broad scope!
:
: So why, when attempting to inherit a form from a base form class, is
: 'Friend' inadequate to give inherited forms 'public'-style access to
: inherited controls? I.E. - i have a base form with two group boxes on it.
: When they are declared 'Friend', i can't drag and drop controls into them
in
: inherited forms in the visual form designer. When they are declared
: 'Protected Friend', they work as expected.
:
: Getting back to the definition of Friend - isn't any inherited form within
: the same project going to be considered "...within the program... [or]
....in
: the same assembly."? By now, my empirical evidence indicates that this
not
: the case, but i am wondering WHY?!
:
: TIA! =)
:
:
Nov 20 '05 #2

P: n/a
If the class that derives from DataEntryForm is in the same assembly (same
exe or same dll) as DataEntryForm, any friend member on DataEntryForm
should be accessible by it - can you show us the code that tries to access,
and what is the error it gives?

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.