Well, I messed around with your project a little and got it working, but there's a lot of things that you do differently than how I normally program.
For starters, when disposing of a form in mobile you want to use .DisposeOf, not FreeAndNil. See this link, especially:
there are scenarios when you need to execute the destructor code right away, regardless of the fact that there might be other pending references to the object. [...] the new compiler introduces a dispose pattern:
MyObject.DisposeOf
;
Another thing I noticed is that your Unit3 creates Form4. But then you have Unit4 accessing the memo in Unit3. I hope that's just for demo purposes as I don't think that sort of design is suggested.
So, short summary of how I got it to work: I set up a TNotifyEvent
in Form4 for when it is finished:
procedure TForm4.Button1Click(Sender: TObject);
begin
if assigned(FOnCloseEvent) then
FOnCloseEvent(Self);
end;
In Uni3, I setup a handler when the form is created:
MyForm.OnCloseEvent := CloseEvent;
The event triggers this code:
procedure TForm3.CloseEvent(Sender: TObject);
begin
if assigned(MyForm) then
MyForm.DisposeOf;
end;
I also made MyForm
a private object of TForm3
as opposed to local variable.
With these changes I can hit show and close as long as I want and the form will always show quickly. There could be better ways to do this, if there are let me know!