我要更改的是我的代表或我的活动进行的什么? [英] What have I to change, that my delegate or my event works?

查看:70
本文介绍了我要更改的是我的代表或我的活动进行的什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我的任务是将IDisp类中Tick方法中的日期值带到Subscriber类中的函数中.例如:trüber或trans.

为此,我创建了一个可以传递datevalue的适应性事件.所以我想从订户类订阅此事件.但这不起作用.

然后,我的另一个计划是建立一个委托,该委托在每一个滴答处都调用函数trüber并给出日期值.

不幸的是,第一个计划和第二个计划都不起作用.
但是,这不是编译器错误,所以我不知道为什么委托不起作用.

坦克的每一个帮助.



Hi everyone,
my task is to bring the date value from the Tick Method in the IDisp class in a function from the Subscriber class. e.g.: trüber or trans.

For this purpose i created an adapted event that could deliver the datevalue. So i want to subscribe to this event from the subscriber class. But it doesnt work.

My other plan was then to build an delegate which calls at every tick the function trüber and gives the date value.

Unfortunately neither the first nor the second plan does work.
But ther is no compiler error so i dont know why the delegate doesnt work.

Tanks for every help.

Ben

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Regalüberwachung
{
    public class MyEventArgs : EventArgs
    {
        private string m_Message = "";
        public string spub ="";
        public MyEventArgs(string Message)
        { 
        
        }
              
       public string Message
       {
                      get { return m_Message; }
       }
                
    }
    public delegate void Movemyarray(object sender, MyEventArgs ee);
    public delegate void mydelll(string  trans);
    public class Subscriber
    {
        
        public string transfersub;
        protected string[] args;
        protected App app = null;
        public FormNew myForm = null;
        App.ClockI clo = new App.ClockI();
        public Subscriber(string[] a)
        {
            transfersub = clo.transferstring;
            clo.dellli = new mydelll(trans);
            setArgs(a);
           // clo.moveit +=new Movemyarray(receiv );
            
            
        }

        
        public void trüber()
        {
            string sss;
            sss = clo.transferstring;

        }

        public void trans(string s)
        {
            string a;
            a = s;
            
        }
               
        public int getvalues()
        {
            int i;
            i=1;
            return i;
        }

        public void setArgs(string[] a)
        {args = a;      }

        public void setFormHandle(FormNew form)
        {           myForm = form;      }

        public void shutdown()
        {        app.subscriberStop();        }
       
        
        public class App : Ice.Application
        {
            
                    
            public class ClockI : ClockDisp_
            {
                public string transferstring;
                public event Movemyarray moveit;
                public  mydelll  dellli;
                                         
                public override void tick(string date, Ice.Currentrrent)
                {
                    transferstring = date;
                    System.Console.Out.WriteLine(date);
                   
                    moveit(this, new MyEventArgs(date));
                    dellli(date);
                 }  

推荐答案

我可以看到您创建了一个委托,但是我从未见过您使用+ =语法分配您的委托来调用方法.
I can see you create a delegate, but I don''t see you ever using the += syntax to assign your delegate to call a method.


您为什么注释该行
//clo.moveit + = new Movemyarray(receiv);
您应该创建一个Movemyarray类型的委托并将该委托附加到事件上.
取消注释注释的代码,并添加诸如
的方法接收
无效接收(对象发送者,MyEventArgs e)
{
//在这里做你的逻辑
}
why did you comment the line
// clo.moveit +=new Movemyarray(receiv );
You should create a delegte of the Movemyarray type and attach this delegate to the event.i.e.;
uncomment the commented code and add a method receiv like

void receiv (object sender,MyEventArgs e)
{
// Do your logic here
}


这篇关于我要更改的是我的代表或我的活动进行的什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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