Title has it. How do I send data from a modal screen (dialog) to another screen? Or from one screen to another? Or set a string to open when launching a second screen?
With delegates.
need more help with delegates.
Iâve thought of writing to a special folder (resource or documents). Doesnât seem to work in the virtual iOS device. Perhaps on a real device.
Donât do that. Itâs a huge waste of resources.
If all youâre doing is sending data from a parent screen to a detail screen, you just need to put a property in the detail screen to hold the item and use it in the opening event to set up things the way you need to. Then when creating that screen later you do something like this:
Var detail as new DetailScreen
Detail.propertyName = dataToTransfer
Self.pushTo(detail)
If however you need a two-way communication, delegates are certainly one way to go. Basically you can create a delegate on a class and then pass a pointer to a method that matches the delegate signature when the class needs to send data, it can check to see if the delegate property has been set and if so, call the corresponding method. xojo has examples on how delegates work.
Here is a Xojo example using delegates:
thanks, will try that.
Wow, looks simple. Still donât understand declares, but this doesnât look complicated. Will use it, then look carefully to try to understand.
Declares and Delegates are two completely different things.
Can the âself.pushto()â function address the original screen, not a new screen? When I use this repeatedly get a stack of screens (alternating parent and modal). Not great.
Besides Gregâs example, you can also communicate with existing screens to execute a method or change a property.
MasterScreen(Self.ParentSplitView.Master).ContinueButtonState(True)
Thatâs what my example is doing. Self is the current screen, detail is the new screen.
But it seems that I gave you the deprecated method. The new one would be:
Detail.Show(Self)
Perhaps Iâm not understanding. When I replace self.push() with âdetail.showâ, I still get stacked screens. The problem is that detail is a newly created screen, not the original parent. Need a way to reference the parent, which isnât obvious.
Also tried to implement the declare method; this fails since, for some reason, the constructor for the modal screen doesnât fire. (the example works perfectly; but when I insert the code into my screens, which are fairly complex, the constructor doesnât fire).
(the 'parent.splitview function doesnât work since the parent isnât a split view; just a parent).
thanks for the help, but remain frustrated
Perhaps Iâm not. Could you show a screenshot of what is wrong? FWIW, modal views do appear on top of others on iOS.
Itâs very important that we get the terminology corrected here because using the word âdeclareâ means something completely different. What weâre talking about is a delegate.
Then use another method or event. Opening should work or just make a method that you call when you create it.
yes, showmodal produces a model screen on top of the calling screen. The issue is having the modal change something in the calling screen. (screens are embarassing).
The lines I get to work a bit always start with âVar detail as new DetailScreenâ which creates a new detail screen and doesnât address the parent. Also results in stacked screens, which I donât want.
my bad. I meant delegate, not declare. I was pretty careful in the implementation (not in writing the post above).
Iâll try making a new method. Not very clear about the scope of what constructors do.
thanks for your help.
(by the way, the app works pretty well in single screen mode. but a modal screen would make whatâs going on much clearer to users; the app is a port of a desktop and web app that is a two-way atlas in neuroanatomy. Current images looks something like this).
The fact that the constructors donât fire is a bug, but not something you can work around.
Thereâs a trick we can use to make this all a little easier since objects are always passed by reference.
-
Make a property on the detail screen whose type is MobileScreen, named Parent.
-
Add a new method to the detail screen:
ShowModal( parent As MobileScreen, style As ModalPresentationStyles = ModalPresentationStyles.Automatic, animate As Boolean = True)
With the code:
Self.ParentScreen = Parent
Super.ShowModal(parent, style, animate)
Now, in your detailscreen, when you need to do something on the main screen, you can just do
MainScreen(parent).methodName
Now Iâm going to suggest that you make special methods just for this purpose. Donât modify controls and properties directly.
Also, in any place where you close the dialog, you should set parent = Nil
.
sounds good. tomorrow.
thanks again.
Not working.
Iâve added a line (line 2, below, in asterisks) from the parent screen.
var adetail as new detail
adetail.parent=self
adetail.ShowModal
Now parent in detail screen is a reference to the main screen. (when I pause, parent is a ref to parent).
the code you suggested:
MainScreen(parent).methodName
doesnât work. After the period, if I enter a method in the parentscreen, it says it doesnât exist. Tab after the periodgives native functions, like âcloseâ, but no methods.
Is the method on MainScreen marked as Public?
Just FYI - autocomplete is wrong sometimes. If youâre sure the thing is right, type it and Run. The compiler will tell you whatâs actually going on.
How is Parent defined? If it is simply Window, then you need to cast it to the proper window type in order to call the method.