PDA

Click to See Complete Forum and Search --> : *** RESOLVED *** Implementing a method


finn0013
Aug 14th, 2006, 09:27 AM
I am new to C# and am having trouble translating the following line from VB.net to C#:


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
' Do stuff...
End Sub


What I have so far is:

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?

finn0013
Aug 14th, 2006, 09:52 AM
Nevermind... I was trying to return void when it really returned Boolean...

jmcilhinney
Aug 14th, 2006, 06:33 PM
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.

finn0013
Aug 14th, 2006, 07:17 PM
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.

jmcilhinney
Aug 14th, 2006, 07:20 PM
Passing by value (in only) is the default and you explicitly specify 'ref' (in/out) or 'out' (out only).

DNA7433
Aug 15th, 2006, 05:59 PM
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.

finn0013
Aug 16th, 2006, 07:26 AM
That makes more sense to me. Thanks for the clarification.