Results 1 to 7 of 7

Thread: *** RESOLVED *** Implementing a method

  1. #1

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222

    Resolved *** RESOLVED *** Implementing a method

    I am new to C# and am having trouble translating the following line from VB.net to C#:

    VB Code:
    1. Public Sub BeforeNavigate2(ByVal pDisp As Object, ByRef URL As String, ByRef flags As Object, ByRef targetFrameName As String, ByRef postData As Object, ByRef headers As String, ByRef cancel As Boolean) Implements DWebBrowserEvents2.BeforeNavigate2
    2.     ' Do stuff...
    3. End Sub

    What I have so far is:
    VB Code:
    1. public void BeforeNavigate2(Object pDisp, String URL, Object flags, String targetFrameName, Object postData, String headers) {  // Do stuff... }

    But when compiling, I get the following error:
    Error 1 'ModifiableWebBrowser.WebBrowserExtendedEvents' does not implement interface member 'ModifiableWebBrowser.DWebBrowserEvents2.BeforeNavigate2(object, string, object, string, object, string)'. 'ModifiableWebBrowser.WebBrowserExtendedEvents.BeforeNavigate2(object, string, object, string, object, string)' is either static, not public, or has the wrong return type. C:\Documents and Settings\jmcdonald\My Documents\Visual Studio 2005\Projects\WindowsApplication3\WindowsApplication3\ModifiableWebBrowser.cs 81 18 WindowsApplication3


    I know that I need to tell the app that this method is implementing the DWebBrowserEvents2.BeforeNavigate2 method, but can not figure out the syntax. I have searched for the syntax for this but must be searching by the wrong criteria as I have not found anything yet. Help?
    Last edited by finn0013; Aug 14th, 2006 at 09:52 AM.

  2. #2

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222

    Re: Implementing a method

    Nevermind... I was trying to return void when it really returned Boolean...

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: *** RESOLVED *** Implementing a method

    You've also got to include the 'ref' keyword before the arguments that are ByRef in the VB code. Note that you also need to add the 'ref' keyword befroe the parameter when you call the method.

  4. #4

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222

    Re: *** RESOLVED *** Implementing a method

    Thanks, I didn't know that. I assumed that every object was passed by reference unless you specifically specified to pass by value - java habits.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: *** RESOLVED *** Implementing a method

    Passing by value (in only) is the default and you explicitly specify 'ref' (in/out) or 'out' (out only).

  6. #6
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: *** RESOLVED *** Implementing a method

    It's really the reference to the object that's passed by reference. If you pass an object by value you can still change it's data in the method and have those changes visible in the caller. It's a lot different than in the days of C++. Passing by reference simply allows you to assign a new object to that variable and have that assignment reflected in the calling method too.
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  7. #7

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222

    Re: *** RESOLVED *** Implementing a method

    That makes more sense to me. Thanks for the clarification.

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