Hello,

I will try to ask this question very straight forward to not complicate the example.
As seen the an event called currentTime is located INSIDE a public class EWrapperImpl.
The functions comes from a DLL reference file that I code against. By default it seems
that the currentTime(long time) has to be declared in the EWrapperImpl class.

I wonder if there are any standard procedure to be able to let this currentTime event
to Also run in the "public partial class Form1 : Form" somehow?

public class EWrapperImpl : EWrapper
{
    public void currentTime(long time) { }
}

What wonder is how it would be possible to have this event in the "public partial class Form1 : Form"
which is the application itself.

Can we declare the currentTime event in the below code somehow?

namespace TestCsharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeCompo nent();
        }

        //How is it possible to declare below function here?: 

        //"public void currentTime(long time) { }"
    }
}

Recommended Answers

All 4 Replies

Hi

Not sure I fully understand how you want to work with the currentTime method based on your description. But in the most simple terms, you would declare a type of EWrapperImpl in your form class and then call currentTime:

            EWrapperImpl ewrap = new EWrapperImpl();
            ewrap.currentTime(...);

HTH

Is there any special raison to implement your own current time, when this functionality already exists? Example.

Is there any special raison to implement your own current time, when this functionality already exists? Example.
EDIT: Please can this post be deleted?

Thanks for answer,

Yes, I will put the complete code to fully understand how I work with the currenttime.

Below is the so called EWrapperImpl class. This class has many events. I have just taken currenttime as an example.
The thing is that the class events like currenttime on intervals is returning the currenttime without calling any method.

public class EWrapperImpl : EWrapper
{
    public void currentTime(long time) 
    {
             Form1 form1 = new Form1();
      form1.functionNeedingGlobalValue(time);
    }
}

I do use an API that connects to a server with the below code in the "button1_Click"

namespace TestCsharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        String globalvalue = "";
        private void button1_Click(object sender, EventArgs e)
        {
            EWrapperImpl client = new EWrapperImpl();

            globalvalue = "hello";
            client.ClientSocket.eConnect("127.0.0.1", 7496, 0); //Connect to server
        }
        public void functionNeedingGlobalValue(long time)
        {
            MessageBox.Show(time.ToString() + "," + globalvalue);
        }
    }
}

If we take the above example, when I click on the button1_Click, this connects to the server. Then the currentime
returns the time value on the server. The thing is that I need to call "functionNeedingGlobalValue" which will also use
the "globalvalue".
In the above when "functionNeedingGlobalValue" is called the "globalvalue" is == "" even that it was set to "hello"
in the button1_Click.
I wonder why this happens?

However if I delcare like this instead:

static String globalvalue = "";

Then "hello" will be shown.
I think this leaves me with 2 questions. Is it a good practise to put static infront of all 100 global variables that
I have that is called in the same way as the above example or is there a way to declare this function in the form class to set and get
global values?

public void currentTime(long time)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.