Results 1 to 12 of 12

Thread: [2005] Confused on this concept, need help understanding.

  1. #1

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    [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.

  2. #2

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    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.

  3. #3
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    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?

  4. #4

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    Re: [2005] Confused on this concept, need help understanding.

    Quote 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.

  5. #5
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: [2005] Confused on this concept, need help understanding.

    Quote 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.

  6. #6

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  8. #8
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: [2005] Confused on this concept, need help understanding.

    Quote 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.
    Quote 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.

  9. #9

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    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.

  10. #10

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    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.

  11. #11

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    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.

  12. #12
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    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
  •  



Click Here to Expand Forum to Full Width