How to create a Basic4ppc library

Discussion in 'Code Samples & Tips' started by Erel, May 1, 2007.

  1. Discorez

    Discorez Member Licensed User

    Please, help me with events...

    I created C# DLL with simple class for testing event:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace EventHandlersTest
    {
        
    public delegate void MyEventHandler();
            
        
    public class MyEvent
        {
            
    public event MyEventHandler SomeEvent;

            
    public void OnSomeEvent()
            {
                
    if (SomeEvent != null)
                    SomeEvent();
            
    }

            public void Test(int X)
            {
                    if (X == 10)
                        OnSomeEvent();
            }
        }
    }
    B4PPC code:
    (ME - MyEvent.dll)
    Code:
    Sub App_Start
       Form1.Show
       ME.New1
    End Sub

    Sub Button1_Click
      ME.Test(
    10)
    End Sub

    Sub ME_OnSomeEvent
      
    Msgbox("SomeEvent!")
    End Sub
    But, if I clicked on Button1, event OnSomeEvent doesn't work.
    How to correct?
    :sign0085:
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Discorez

    Discorez Member Licensed User

    Erel, unfortunately, still it is not clear... In an example, event is anchored to already available event of ScrollBar, but in my case, event is required for the self class. I tried various variants, but I receive either an error, or event doesn't work in B4PPC...
    I will be grateful, if somebody helps with example on a C #.
     
  4. agraham

    agraham Expert Licensed User

    Like this I think. Compare it to the ScrollBar code.

    Code:
    namespace EventHandlersTest
    {
             // at runtime tells Basic4ppc what 
    event has occurred
            
    private object[] SomeEventEventObject;

     
            // at compile times identifies the 
    event to Basic4ppc
            // at runtime Basic4ppc sets this 
    to its event handler
           
    public event EventHandler SomeEvent; 

          
            
    public class MyEvent
            {
                SomeEventEventObject = new object[] { this, 
    "SomeEvent" };
            }

            public void OnSomeEvent()
            {
                if (SomeEvent != null)
                    SomeEvent();
            }

            public void Test(int X)
            {
                    if (X == 10)
                        OnSomeEvent();
            }
        }
    }
     
  5. Discorez

    Discorez Member Licensed User

    agraham, Your example isn't compiled (~4 errors)
    My project (VS 2008) in attach.
     

    Attached Files:

  6. agraham

    agraham Expert Licensed User

    Sorry, I knocked it up from memory without testing it, but it's really not complicated.

    Code:
    public class MyEvent
        {
            
    private object[] SomeEventEventObject;
            
    public event EventHandler SomeEvent;

           
    public MyEvent()
            {
                 SomeEventEventObject = new object[] { this, 
    "SomeEvent" };
            }

            public void OnSomeEvent()
            {
                if (SomeEvent != null)
                    SomeEvent(SomeEventEventObject, null); 
            }

            public void Test(int X)
            {
                if (X == 10)
                    OnSomeEvent();
            } 

        }
     
  7. Discorez

    Discorez Member Licensed User

    agraham, many thanks!
    All perfectly works! All problems was here -
    Code:
    SomeEvent(SomeEventEventObject, null);
    I did a call SomeEvent() without arguments...
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice