Robert Valentino Well-Known Member Licensed User Longtime User Apr 30, 2019 #1 I have a designer layout that I only need to load when a user asks for it - once loaded it stays around for later use Code: Private sPI_Partners_Main As Panel Private sPI_Partners_Panel As Panel Private sPI_Partners_Title As Label Private sPI_Partners_List As ListView Private sPI_Partners_OK As Button I use to do the following: Code: If sPI_Partners_Main.IsInitialized = False Then sPI_Partners_Main.Initialize("") mPlayerInfoPanel.AddView(sPI_Partners_Main, 0, 0, 100%x, 100%y) sPI_Partners_Main.LoadLayout("sPI_PartnersList") end if But doing the above code kept giving me Warning #20 - was added with designer should not be initialized I do not like over-riding warnings because I could miss something (and at 68+ I am missing a lot). So I changed the code to this Code: If sPI_Partners_Main.IsInitialized = False Then Dim LoadPanel As Panel LoadPanel.Initialize("") mPlayerInfoPanel.AddView(LoadPanel, 0, 0, 100%x, 100%y) LoadPanel.LoadLayout("sPI_PartnersList") sPI_Partners_Main = LoadPanel.GetView(0) end if NOW the new code works fine and gets rid of the Warning #20 but looks convoluted What is the proper way to load a designer layout dynamically. BobVal
I have a designer layout that I only need to load when a user asks for it - once loaded it stays around for later use Code: Private sPI_Partners_Main As Panel Private sPI_Partners_Panel As Panel Private sPI_Partners_Title As Label Private sPI_Partners_List As ListView Private sPI_Partners_OK As Button I use to do the following: Code: If sPI_Partners_Main.IsInitialized = False Then sPI_Partners_Main.Initialize("") mPlayerInfoPanel.AddView(sPI_Partners_Main, 0, 0, 100%x, 100%y) sPI_Partners_Main.LoadLayout("sPI_PartnersList") end if But doing the above code kept giving me Warning #20 - was added with designer should not be initialized I do not like over-riding warnings because I could miss something (and at 68+ I am missing a lot). So I changed the code to this Code: If sPI_Partners_Main.IsInitialized = False Then Dim LoadPanel As Panel LoadPanel.Initialize("") mPlayerInfoPanel.AddView(LoadPanel, 0, 0, 100%x, 100%y) LoadPanel.LoadLayout("sPI_PartnersList") sPI_Partners_Main = LoadPanel.GetView(0) end if NOW the new code works fine and gets rid of the Warning #20 but looks convoluted What is the proper way to load a designer layout dynamically. BobVal
Erel B4X founder Staff member Licensed User Longtime User May 1, 2019 #2 Based on the warning there is a control named SPI_Partners_Main in one of the layout files. This does sound like a programming mistake. Upvote 0
Based on the warning there is a control named SPI_Partners_Main in one of the layout files. This does sound like a programming mistake.
Robert Valentino Well-Known Member Licensed User Longtime User May 1, 2019 #3 "programming mistake", not sure what you mean. This is a layout I load when needed (as stated above). Either I am not explaining correctly? The actual code is above in post #1 Upvote 0
"programming mistake", not sure what you mean. This is a layout I load when needed (as stated above). Either I am not explaining correctly? The actual code is above in post #1
Robert Valentino Well-Known Member Licensed User Longtime User May 1, 2019 #4 I guess I could move panel code (shown below) to my Main Panel and have it load with that. But this panel is shown so infrequently that I thought it would be best to load when needed Code: Private sPI_Partners_Main As Panel Private sPI_Partners_Panel As Panel Private sPI_Partners_Title As Label Private sPI_Partners_List As ListView Private sPI_Partners_OK As Button Upvote 0
I guess I could move panel code (shown below) to my Main Panel and have it load with that. But this panel is shown so infrequently that I thought it would be best to load when needed Code: Private sPI_Partners_Main As Panel Private sPI_Partners_Panel As Panel Private sPI_Partners_Title As Label Private sPI_Partners_List As ListView Private sPI_Partners_OK As Button
walterf25 Expert Licensed User Longtime User May 1, 2019 #5 What Erel is explaining, is that the warning you are receiving is due to the fact that you have already added one or more of the views on your layout, so there is no need to Initialize the view, for example I see in your code you have this line Code: sPI_Partners_Main.Initialize("") If this panel was added to your layout file using the Visual Designer, then there is no need to manually Initialize it in your code. Walter Upvote 0
What Erel is explaining, is that the warning you are receiving is due to the fact that you have already added one or more of the views on your layout, so there is no need to Initialize the view, for example I see in your code you have this line Code: sPI_Partners_Main.Initialize("") If this panel was added to your layout file using the Visual Designer, then there is no need to manually Initialize it in your code. Walter
Robert Valentino Well-Known Member Licensed User Longtime User May 1, 2019 #6 I understand. But this panel is not loaded when I load my main layout. if I were to do a sPI_Partners_Main.LoadLayout("sPI_PartnersList") I would crash because sPI_Partners_Main is NOT Initialized I guess I'm just not explaining it right. So let me try again. I have a splayerinfo.bal which is loaded with Activity.LoadLayout("splayerinfo") and contains about 50 different buttons, toggles, etc I also have spi_partnerslist.bal which I only need to load when needed and contains the 5 screen fields described above Now sPI_Partners_Main is in the spi_partnerslist.bal file so it was created with designer but because I haven't loaded the .bal file is isn't initialized It's NOT initialized because I haven't loaded the .bal file so I can't do a LoadLayout on it because it's not initialized, and if I initialize it then I get the warning that it is initialized in designer. Hench I did the following code to get around it: Code: If sPI_Partners_Main.IsInitialized = False Then Dim LoadPanel As Panel LoadPanel.Initialize("") mPlayerInfoPanel.AddView(LoadPanel, 0, 0, 100%x, 100%y) LoadPanel.LoadLayout("sPI_PartnersList") sPI_Partners_Main = LoadPanel.GetView(0) end if HOW do you load a layout that is NOT part of the Activity Layout Upvote 0
I understand. But this panel is not loaded when I load my main layout. if I were to do a sPI_Partners_Main.LoadLayout("sPI_PartnersList") I would crash because sPI_Partners_Main is NOT Initialized I guess I'm just not explaining it right. So let me try again. I have a splayerinfo.bal which is loaded with Activity.LoadLayout("splayerinfo") and contains about 50 different buttons, toggles, etc I also have spi_partnerslist.bal which I only need to load when needed and contains the 5 screen fields described above Now sPI_Partners_Main is in the spi_partnerslist.bal file so it was created with designer but because I haven't loaded the .bal file is isn't initialized It's NOT initialized because I haven't loaded the .bal file so I can't do a LoadLayout on it because it's not initialized, and if I initialize it then I get the warning that it is initialized in designer. Hench I did the following code to get around it: Code: If sPI_Partners_Main.IsInitialized = False Then Dim LoadPanel As Panel LoadPanel.Initialize("") mPlayerInfoPanel.AddView(LoadPanel, 0, 0, 100%x, 100%y) LoadPanel.LoadLayout("sPI_PartnersList") sPI_Partners_Main = LoadPanel.GetView(0) end if HOW do you load a layout that is NOT part of the Activity Layout
klaus Expert Licensed User Longtime User May 1, 2019 #7 Post a small project showing the problem, this would be much more efficient. Upvote 0
walterf25 Expert Licensed User Longtime User May 1, 2019 #8 Robert Valentino said: if I were to do a sPI_Partners_Main.LoadLayout("sPI_PartnersList") I would crash because sPI_Partners_Main is NOT Initialized Click to expand... Are you saying that sPI_Partners_Main is a panel that you added to a layout with the Visual Designer? So basically you want to load another layout to a panel that is in a different layout? If that is the case that is a very unusual way of doing things, if you are trying to load different layout, why don't you just create separate activities and load the required layouts in each separate activity, I think this will make things way easier. Walter Upvote 0
Robert Valentino said: if I were to do a sPI_Partners_Main.LoadLayout("sPI_PartnersList") I would crash because sPI_Partners_Main is NOT Initialized Click to expand... Are you saying that sPI_Partners_Main is a panel that you added to a layout with the Visual Designer? So basically you want to load another layout to a panel that is in a different layout? If that is the case that is a very unusual way of doing things, if you are trying to load different layout, why don't you just create separate activities and load the required layouts in each separate activity, I think this will make things way easier. Walter
Robert Valentino Well-Known Member Licensed User Longtime User May 1, 2019 #9 Yes to sPI_Partners_Main being a panel that is a layout added with VD Why would I need another activity. The users asks for some action. I do the action and load and display the information then close the panel when complete. There is no reason for another activity. Think of this like a directory picker. When you call FilePicker it loads a list of directories and displays it. You aren't starting another activity it is just displaying another panel on top of your main panel and gets closed when done. My users may only ask for this information once in 1000 times, if ever. So I only load this panel when needed. Once loaded I would reuse it if they requested it again in the same session. I could add all these fields to my main panel and have them set as Visible = false and Enabled = false. But why load all the extra fields if they aren't being used. BOTH my examples in Post #1 work perfectly. Doing it like I did in the first "If" generates the Warning #20. Doing it like I did in the second "If" work perfectly with No warning. But seems a lot more complex then the actual task I need to do. I'm doing a small project but it is basically the code from Post 1 Upvote 0
Yes to sPI_Partners_Main being a panel that is a layout added with VD Why would I need another activity. The users asks for some action. I do the action and load and display the information then close the panel when complete. There is no reason for another activity. Think of this like a directory picker. When you call FilePicker it loads a list of directories and displays it. You aren't starting another activity it is just displaying another panel on top of your main panel and gets closed when done. My users may only ask for this information once in 1000 times, if ever. So I only load this panel when needed. Once loaded I would reuse it if they requested it again in the same session. I could add all these fields to my main panel and have them set as Visible = false and Enabled = false. But why load all the extra fields if they aren't being used. BOTH my examples in Post #1 work perfectly. Doing it like I did in the first "If" generates the Warning #20. Doing it like I did in the second "If" work perfectly with No warning. But seems a lot more complex then the actual task I need to do. I'm doing a small project but it is basically the code from Post 1
Robert Valentino Well-Known Member Licensed User Longtime User May 1, 2019 #10 Here's an example showing what I am doing ALSO remember this is a Question about Initializing and loading a layout Attachments Test_ScreenLoad.zip Test_ScreenLoad.zip 10.8 KB · Views: 597 Upvote 0
Here's an example showing what I am doing ALSO remember this is a Question about Initializing and loading a layout
Robert Valentino Well-Known Member Licensed User Longtime User May 1, 2019 #11 I guess what I should have done was ask for a new function like: Initialize2(<event>) or ' just initialize no complier warning Initialize2(<event>, <Layout Name>) ' that would initialize and load the layout and no compiler warning Upvote 0
I guess what I should have done was ask for a new function like: Initialize2(<event>) or ' just initialize no complier warning Initialize2(<event>, <Layout Name>) ' that would initialize and load the layout and no compiler warning
Erel B4X founder Staff member Licensed User Longtime User May 2, 2019 #12 Robert Valentino said: programming mistake", not sure what you mean Click to expand... A bug in your code. This is indeed the case here. The first panel (Panel_SubPanel_Main) in the layout is not needed. Remove it and everything will work correctly. Upvote 0
Robert Valentino said: programming mistake", not sure what you mean Click to expand... A bug in your code. This is indeed the case here. The first panel (Panel_SubPanel_Main) in the layout is not needed. Remove it and everything will work correctly.
klaus Expert Licensed User Longtime User May 2, 2019 #13 There is no need to add any other Panel on the main Activity to load SubPanel.bal, you should load the layout directly onto the Activity. You should not position the views in the code! You should position them in the DesignerScript and use Anchors. For example, the code below: Code: Panel_SubPanel_Main.Left = 0 Panel_SubPanel_Main.Top = 0 Panel_SubPanel_Main.Width = 100%x Panel_SubPanel_Main.Height = 100%y Should be replaced by setting the two Anchors: Attached you find a modified version of your test project. Attachments Test_ScreenLoad1.zip Test_ScreenLoad1.zip 11 KB · Views: 631 Upvote 0
There is no need to add any other Panel on the main Activity to load SubPanel.bal, you should load the layout directly onto the Activity. You should not position the views in the code! You should position them in the DesignerScript and use Anchors. For example, the code below: Code: Panel_SubPanel_Main.Left = 0 Panel_SubPanel_Main.Top = 0 Panel_SubPanel_Main.Width = 100%x Panel_SubPanel_Main.Height = 100%y Should be replaced by setting the two Anchors: Attached you find a modified version of your test project.
Robert Valentino Well-Known Member Licensed User Longtime User May 2, 2019 #14 Interesting, Klaus. thank you Upvote 0