Where to put delegate in Script?

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
rantanplan
Posts: 4
Joined: Tue Mar 13, 2012 3:49 am

Where to put delegate in Script?

Post 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

Henrik Sandaker Palm
Posts: 1
Joined: Tue Mar 13, 2012 5:52 am

Re: Where to put delegate in Script?

Post 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.

Skylar
Posts: 42
Joined: Wed Jan 04, 2012 11:17 am

Re: Where to put delegate in Script?

Post 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.
Best Regards,

Beijer Electronics, Inc.
Skylar Walker | Applications Engineer

rantanplan
Posts: 4
Joined: Tue Mar 13, 2012 3:49 am

Re: Where to put delegate in Script?

Post 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

Skylar
Posts: 42
Joined: Wed Jan 04, 2012 11:17 am

Re: Where to put delegate in Script?

Post 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.
Best Regards,

Beijer Electronics, Inc.
Skylar Walker | Applications Engineer

rantanplan
Posts: 4
Joined: Tue Mar 13, 2012 3:49 am

Re: Where to put delegate in Script?

Post 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?

Skylar
Posts: 42
Joined: Wed Jan 04, 2012 11:17 am

Re: Where to put delegate in Script?

Post 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
Best Regards,

Beijer Electronics, Inc.
Skylar Walker | Applications Engineer

User avatar
Ron L.
Posts: 214
Joined: Fri Jul 15, 2011 3:21 pm

Re: Where to put delegate in Script?

Post 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.
Attachments
DynamicComboBoxStrings.zip
(34.77 KiB) Downloaded 611 times
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer

rantanplan
Posts: 4
Joined: Tue Mar 13, 2012 3:49 am

Re: Where to put delegate in Script?

Post by rantanplan »

Thanks Skylar and Ron for your help, I'm still working on it!

Mike

Post Reply