|
-
Jul 16th, 2008, 09:51 AM
#1
Thread Starter
Hyperactive Member
[2005] Confused on this concept, need help understanding.
I have a VB.net Class, with a method declared:
Code:
Protected Friend Overridable Sub KillThreads
In my windows forms, I can go "Myclass.KillThreads"
Now, I have ASP.Net Class, with a functioned declared:
Code:
Protected Friend Shared Function GetUserLoginInfoLogin
In my Web Form, I cannot go "MyClass.GetUserLoginInfoLogin".
I am wondering why I cannot access this method.
-
Jul 16th, 2008, 10:04 AM
#2
Thread Starter
Hyperactive Member
Re: [2005] Confused on this concept, need help understanding.
NM, I don't think a Shard Function should be declared as "protected friend". Doing some research, it seems like most put "Shared Function".
However, not sure why protected friend doesn't work.
-
Jul 16th, 2008, 11:43 AM
#3
Fanatic Member
Re: [2005] Confused on this concept, need help understanding.
"Protected Friend Shared Function" would work only if the class you are calling it from is derived from the class containing that method. Is that the case and you are still unable to call the method?
-
Jul 16th, 2008, 12:08 PM
#4
Thread Starter
Hyperactive Member
Re: [2005] Confused on this concept, need help understanding.
 Originally Posted by rjv_rnjn
"Protected Friend Shared Function" would work only if the class you are calling it from is derived from the class containing that method. Is that the case and you are still unable to call the method?
Yep, I believe so.
Here is a code snippet:
Code:
'class
Public Class Data
Protected Friend Shared Function GetUserLoginInfoLogin(etc etc) as SQLDatatreader
End Function
End Class
'web form
SQLDataReader = Data. <-----only Equals and Reference Equals show up
If I make if Public or just Shared Function it works fine. Just trying to understand VB.Net and ASP.Net.
-
Jul 16th, 2008, 01:53 PM
#5
Fanatic Member
Re: [2005] Confused on this concept, need help understanding.
 Originally Posted by maikeru-sama
If I make if Public or just Shared Function it works fine. Just trying to understand VB.Net and ASP.Net.
In the code snippet you've posted it's not clear whether the "web form" inherits from class "Data" or not. Let's say we have a base class like below:
Code:
Public Class MyBasePage
Inherits System.Web.UI.Page
Protected Friend Shared Function testFunction() As String
Return String.Empty
End Function
End Class
We have another page which derives from this base class.
Code:
Partial Class MyInheritedPage
Inherits MyBasePage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyBasePage.testFunction() ''You'll be able to access the protected shared method here.
End Sub
End Class
Now let's consider another web page that doesn't inherit from base page
Code:
Partial Public Class test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyBasePage. ''Here I do not get the method name.
End Sub
End Class
I hope I'm able to make the point.
-
Jul 16th, 2008, 03:19 PM
#6
Thread Starter
Hyperactive Member
Re: [2005] Confused on this concept, need help understanding.
Data is just a Class that will be used to connect to the database and do CRUD.
The Web Form is just a regular Web Form and does not inherit from Data.
When I am in the Web Form, I want to just access the members without having to instantiate a Data Object, but I don't want anyone outside the assembly to access these methods.
This is all part of me learning OOP, so I am trying to make sure I get the basics down.
-
Jul 16th, 2008, 03:53 PM
#7
Re: [2005] Confused on this concept, need help understanding.
While I'm not going to test this out, it's probably the IDE being confused. If you're using protected friend, you might be able to compile it even if you put the member name there. No guarantees.
-
Jul 16th, 2008, 04:26 PM
#8
Fanatic Member
Re: [2005] Confused on this concept, need help understanding.
 Originally Posted by maikeru-sama
The Web Form is just a regular Web Form and does not inherit from Data.
Well then you can not access the Protected methods of Data class.
 Originally Posted by mendhak
If you're using protected friend, you might be able to compile it even if you put the member name there.
If you're trying to access the protected friend method from a non-derived class, the compiler will give an error.
-
Jul 16th, 2008, 04:53 PM
#9
Thread Starter
Hyperactive Member
Re: [2005] Confused on this concept, need help understanding.
Interesting.
Wonder why I can do it in VB.Net?
I wonder if it has to do with it being a shared function?
Regardless, I need to do more research on Visibility.
-
Jul 16th, 2008, 06:01 PM
#10
Thread Starter
Hyperactive Member
Re: [2005] Confused on this concept, need help understanding.
Here is what I am talking about.
VB.Net 2.0 Code:
Code:
'inside of a class
Public Class Class1
Protected Friend Sub TestMe()
End Sub
End Class
'inside of a windows form
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim t As New Class1
t.TestMe() <----intellisense picks this up
End Sub
End Class
ASP.Net
Code:
'class inside of App_Code
Imports Microsoft.VisualBasic
Public Class Data
Protected Friend Sub TestMe()
End Sub
End Class
'inside a windows form
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim m As New Data
m.'<---------------Intelisense not picking it up
End Sub
End Class
In ASP.Net, if I change it to Friend Sub, the compiler says it is private and of course, when it is Protected Friend Sub, the compiler says it is protected.
I just want to get a handle on OOP.
-
Jul 17th, 2008, 08:10 AM
#11
Thread Starter
Hyperactive Member
Re: [2005] Confused on this concept, need help understanding.
FYI,
Thanks for restating your question. I created a simple website with a friend method in the app_code like you have. Then I did a publish website to a folder. I checked the bin folder and there are two dlls. One is app_code.dll. The other is ap_web_(some random code).dll. The second one is where the code behind for the aspx pages is stored. This is probably why the friend can't be seen. They are actually part of two separate dlls. In a windows form app, this would all be compiled as one dll.
I hope this helps.
-
Jul 17th, 2008, 10:59 AM
#12
Fanatic Member
Re: [2005] Confused on this concept, need help understanding.
My thoughts never raced in that direction. Thanks for sharing this info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|