Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Where to put delegate in Script?
PostPosted: Tue Mar 13, 2012 3:52 am 

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

Offline
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


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Tue Mar 13, 2012 5:57 am 

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

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


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Tue Mar 13, 2012 10:04 am 

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

Offline
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


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Tue Mar 13, 2012 7:24 pm 

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

Offline
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


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Wed Mar 14, 2012 9:23 am 

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

Offline
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


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Thu Mar 15, 2012 1:06 am 

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

Offline
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:
public delegate void TimerHandle();

That Timer would run through the process. Therefore, I create TimerProcess script module:
Code:
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:
void Screen1(System.Object sender, System.EventArgs e)
{
   TimerHandle = Globals.TimerProcess.Method1();
}

That’s what I thought currently. Is it possible to do it?


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Thu Mar 15, 2012 12:06 pm 

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

Offline
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://www.beijerelectronicsinc.com/support/ix/forum/viewtopic.php?f=9&t=5

_________________
Best Regards,

Beijer Electronics, Inc.
Skylar Walker | Applications Engineer


 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Thu Mar 15, 2012 12:26 pm 
User avatar

Joined: Fri Jul 15, 2011 3:21 pm
Posts: 214

Offline
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 ... xt(v=vs.71).aspx

I've also attached an example where I had to do something similar.


Attachments:
DynamicComboBoxStrings.zip [34.77 KiB]
Downloaded 310 times

_________________
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
 Profile  
 
 Post subject: Re: Where to put delegate in Script?
PostPosted: Fri Mar 16, 2012 2:24 am 

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

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

Mike


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: