Page 1 of 1
Where to put delegate in Script?
Posted: Tue Mar 13, 2012 3:52 am
by rantanplan
Dear,
It's very first time for me to use iX Developer Script and it really confusing me where to put delegate declare. In my opinion, iX Developer divide every object into many class, and user just add small script into every event handler. So I couldn't found Main program in iX Developer.
Thanks,
Mike
Re: Where to put delegate in Script?
Posted: Tue Mar 13, 2012 5:57 am
by Henrik Sandaker Palm
Each screen or script module is contained in a separate class, in which you can declare your own delegates or variables (this is also where the screen event handlers are put). Main program is not within reach for the end user. It could be found in your project folder to be opened with a text editor, but every change you may do to this file is overwritten on next project verification.
Re: Where to put delegate in Script?
Posted: Tue Mar 13, 2012 10:04 am
by Skylar
Mike,
If you are looking to write a script that will span many screens, have a look at creating it as a script module. But as Henrik said, you don't have access to the main program.
Re: Where to put delegate in Script?
Posted: Tue Mar 13, 2012 7:24 pm
by rantanplan
Thanks Henrik and Skylar,
Actually, I want to create Timer in module script and this timer will be the tick to scan all event in program, and in Timer Event Handler, I will call function of each seperate screen. So, I don't know whether it's feasible to do that without delegate.
Mike
Re: Where to put delegate in Script?
Posted: Wed Mar 14, 2012 9:23 am
by Skylar
Mike,
What exactly are you trying to accomplish with this? Perhaps I could suggest a different solution. The issue you are going to have with updating screens from a module is that screens which aren't displayed don't exist for all intents and purposes. Each time a screen is displayed, a new instance of that screen is created. If you want to manipulate data across all screens, you will want to use tags to store your variables.
Re: Where to put delegate in Script?
Posted: Thu Mar 15, 2012 1:06 am
by rantanplan
Skylar,
Just for the sake of argument, every screen requires a timer with same interval, but each screen has a different task. And, I declare a delegate:
Code: Select all
public delegate void TimerHandle();
That Timer would run through the process. Therefore, I create TimerProcess script module:
Code: Select all
public partial class TimerProcess
{
private static Timer timer;
private static int temp;
static TimerProcess()
{
timer = new Timer();
timer.Interval = 500;
timer.Tick += new EventHandler(TimerProcessHandler);
}
public void Start()
{
timer.Enabled = true;
}
public void Stop()
{
timer.Enabled = false;
}
public void Method1()
{
//task for Screen1 in here
}
private static void TimerProcessHandler(Object send, EventArgs e)
{
//handle each screen task in here
}
}
This would point to any method/function by every Screen Opened event:
Code: Select all
void Screen1(System.Object sender, System.EventArgs e)
{
TimerHandle = Globals.TimerProcess.Method1();
}
That’s what I thought currently. Is it possible to do it?
Re: Where to put delegate in Script?
Posted: Thu Mar 15, 2012 12:06 pm
by Skylar
Mike,
I'm not completely clear on what you are trying to accomplish from the pseudo code that you sent. Have you seen this excellent example of how to use timers?
http://ixtalk.beijerelectronics.com/vie ... hp?f=9&t=5
Re: Where to put delegate in Script?
Posted: Thu Mar 15, 2012 12:26 pm
by Ron L.
It sounds like you want to add a delegate function to an event when a screen is opened and remove the handler when the screen is closed. You may want to review the C# documentation on using events and delegates here:
http://msdn.microsoft.com/en-us/library ... s.71).aspx
I've also attached an example where I had to do something similar.
Re: Where to put delegate in Script?
Posted: Fri Mar 16, 2012 2:24 am
by rantanplan
Thanks Skylar and Ron for your help, I'm still working on it!
Mike