Screens are constructed every time they are shown?

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
charliehbeijer
Posts: 40
Joined: Sat Jun 02, 2012 7:43 am

Screens are constructed every time they are shown?

Post by charliehbeijer »

I gather that screen objects are destroyed when the screen isn't showing, right?

I have a listbox on a screen, which contains information generated by the program. When I switch to another screen, the listbox is destroyed, apparently. So I have to fill the listbox every time the screen is shown. It takes a noticible amount of time.

Is there any way to keep the listbox, or the whole screen, in memory when the screen isn't being shown?

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Screens are constructed every time they are shown?

Post by mark.monroe »

How are you changing screens? Are you closing the screen with the list box? Or are you creating a new screen using the show method?

That screen with the list box will only be destroyed when the C# garbage collector decides it needs more memory, or you close it. Otherwise that screen is still there. It is just covered up by the screen that gets created when you call show screen. If you were to close all the screens on top of that particular screen, then it should still have it's list box full.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

charliehbeijer
Posts: 40
Joined: Sat Jun 02, 2012 7:43 am

Re: Screens are constructed every time they are shown?

Post by charliehbeijer »

I have a number of screens. I have buttons, with their click actions bound to "ShowScreen" in order to switch between screens.

So I'm on screen TestHistoryScreen, and I want to stuff the list box with some initial data. I can't write a constructor, because it says there is already a constructor. I can't access the screen object from elsewhere in the project, all I can get is Globals.TestHistoryScreen, which is apparently an interface, not the actual screen object.

So I do this:

Code: Select all

	public partial class TestHistoryScreen   {
		private  bool loaded = false;
		
		
		void TestHistoryScreen_Opened(System.Object sender, System.EventArgs e)
		{
			if (!this.loaded) 
			{
				for (int i = 0 ; i < 100 ; i++)
				{
					this.TestListBox.AddString(i, "a string " + i);
				}
				this.loaded = true;
			}
		}
	}
OK, so that code should run the first time the screen is opened. But it doesn't, it runs every time the screen is opened. That tells me I'm getting a brand new TestHistoryScreen object every time I switch to it, because the member variable "loaded" is being set to false again.

If I change the "loaded" variable to static, the list box is only stuffed the first time, but then when I switch to a different screen, and back to TestHistoryScreen, the list box is empty. Again, this indicates that I'm getting a new TestHistoryScreen object every time I switch to the screen.

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Screens are constructed every time they are shown?

Post by mark.monroe »

The screen with the list box will only be destroyed when the C# garbage collector decides it needs more memory, or you close it. Otherwise that screen is still there. It is just covered up by the screen that gets created when you call show screen. If you were to close all the screens on top of that particular screen, then it should still have it's list box full.

Every time you call Show screen you are creating another screen.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

charliehbeijer
Posts: 40
Joined: Sat Jun 02, 2012 7:43 am

Re: Screens are constructed every time they are shown?

Post by charliehbeijer »

Then what click action can I use to go to a previously-created screen, not create a new instance of the screen?

If I highlight a button, and go to Actions, under Click, under Screen, and then highlight Show Screen, it says "Navigates to the specified screen". I don't see anything for navigating to a specified instance of a specified screen.

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Screens are constructed every time they are shown?

Post by mark.monroe »

Like I mentioned before, you need to close the screens that are on top of the screen with the filled list box. Your right, there is no way to navigate to a specific instance of a screen.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

Post Reply