如何在ABAP中处理C#事件 [英] How to handle C# events in ABAP

查看:79
本文介绍了如何在ABAP中处理C#事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActiveX用户控件,显示在sapgui中。这很好。



现在我想处理从控件到ABAP代码的事件,实例化控件。



我知道使用VB6和事件ID处理但是如何在ABAP端使用C#?

感谢高级答案

I have an ActiveX user control what is displayed in the sapgui. This works fine.

Now I want to handle an event from the control to the ABAP code what was instantiating the control.

I know the handling with VB6 and the event id but how do it work with C# on ABAP side?
Thanks in advanced for answers

推荐答案

I found the solution if I asked for "C# events in VB6". The main thing is the interface of type dispatch and how to bind it to the class with the code. Here is  the code how I solved this:




using System;
using System.Text;
using System.Runtime.InteropServices;




namespace SceSapGui
{
    public delegate void SceEventHandler(object text, EventArgs e);     // Definition of the event handler body (parameters)


    // Interface 1 (Dispatch)
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]     // This interface is for the event handler (dispatch)
    [GuidAttribute("00000000-0000-0000-0000-000000000001")]             // Anyone needs a different guid
    [ComVisible(true)]                                                  // Make it visible
    public interface ISceSapGuiDispatch
    {
        [DispId(1)]                                                     // Define the eventid
        void SceClicked(object text, EventArgs e);                      // Event definition
    }

    // Interface 2 (Methode and properties)
    [GuidAttribute("00000000-0000-0000-0000-000000000002")]             // Anyone needs a different guid
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]          // This interface is for data in/out
    [ComVisible(true)]                                                  // Make it visible
    public interface ISceSapGui
    {
        void Init(string @URI);                                         // definition of a methode
        string R3ReturnCode { get; }                                    // definition of a readonly property
    }

    [GuidAttribute("00000000-0000-0000-0000-000000000003")]             // Anyone needs a different guid
    [ClassInterface(ClassInterfaceType.None)]                           // Prevent compiler to build automaticaly a default interface
    [ComSourceInterfaces(typeof(ISceSapGuiDispatch))]                   // Attach the dispatch interface (don't know why in this way and not by inheritance like interface2)
    [ComVisible(true)]                                                  // Make it visible
    public partial class SceSapGui : ISceSapGui                         // Main class derived by interface 2
    {
        #region Interface member ISceSapGuiDispatch
        public event SceEventHandler SceClicked;                        // Event handler variable

        protected virtual void OnSceClicked(EventArgs e, string text)   // Call this if you want to raise the event
        {
            if (this.SceClicked != null)                                // but make it only if someone attached to it
                this.SceClicked((object)text, new EventArgs());         // Raise the event
        }
        #endregion

        #region Interface member ISceSapGui
        [ComVisible(true)]
        public void Init(string @URI)
        {
            // ...
        }

        [ComVisible(true)]
        public string R3ReturnCode
        {
            get { return "0"; }
        }

        #endregion
    }

}


这篇关于如何在ABAP中处理C#事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆