Recent

Author Topic: Problem with Showmodal ?  (Read 29496 times)

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Problem with Showmodal ?
« on: October 20, 2010, 11:57:30 am »
Hi,

I have a Mainform and a Secondform, both autocreated.

From the filemanager I start the application.
From within the Mainform I  showmodal the secondform.
That works. However this form also has the X button in the top right corner.
If the user presses that button, the Secondform is hidden (I guess) and the filemanager shows up again. I really would have expected the mainform to show up.

In the taskmanager I can see that both mainform and secondform are still alive. Activating mainform gives me a non-responsive mainform (of course, there is a modal second form out there). Activating via taskmanager) the secondform, and closing it properly does NOT bring be back to the mainform but to the taskmanager.

If I just Show the form (not showmodal) the X-button works as expected.

So.. my question:

What is the best way to showmodal a form and be sure that the X button just closes this form? Or how to get rid of this X-button?

Second: how to make sure there is only one form visible in the taskmanager (the mainform) and if activated there, to be sure that the correct form appears? I mean that IF there is a modal form open, it should NOT be visible in the taskmanager and if the application is activated again in the taskmanager, the modal form should appear, shouldn't it?

tia!
John
 

BlueIcaro

  • Hero Member
  • *****
  • Posts: 818
    • Blog personal
Re: Problem with Showmodal ?
« Reply #1 on: October 20, 2010, 01:20:09 pm »
Try to remove the second form from automatic list

and then write to call your second form:

Quote
(...)

Uses UnitOfMySecondForm
(...)
Var
 F : TSecondForm;
Begin
 F := TSecondForm.Create (self);
 F.ShowModal;
 F.Free;
End;

/BlueIcaro

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Problem with Showmodal ?
« Reply #2 on: October 20, 2010, 01:27:13 pm »
Hi BlueIcaro

Tried, but as far as I can see it makes no difference.

John

BlueIcaro

  • Hero Member
  • *****
  • Posts: 818
    • Blog personal
Re: Problem with Showmodal ?
« Reply #3 on: October 20, 2010, 01:41:41 pm »
The second form, is a normal form, or a mdi form?

BTW, try onClose Event of the second form:

Quote
CloseAction := caFree;   


/BlueIcaro

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Problem with Showmodal ?
« Reply #4 on: October 20, 2010, 01:49:12 pm »
Nope, caFree is not triggered. The form is not closed when the X-button is pressed.
This X-button hides the application.

What I would like is an OK-button (or even better: NO button at all) on this modal form. I get an OK-button when I set Borderstyle=bsDialog, but then two formcaptions appear and the form is not aligned to the screen.

John

zariq

  • Full Member
  • ***
  • Posts: 109
Re: Problem with Showmodal ?
« Reply #5 on: October 20, 2010, 01:55:31 pm »
Try removing everything from the bordericons property of your second form in the object inspector.  That should leave you with just an ok button and that should close the second form. That's how it works in windows mobile but it could be different for your case.

Zariq.

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Problem with Showmodal ?
« Reply #6 on: October 20, 2010, 03:32:14 pm »
Hi Zariq,

No OK-button, but no X either  :)
Unfortunately the size is not ok yet (but I can workaround that).
Worse is that taskmanager shows both mainform and secondform.
Activating the secondform, it appears, but when closing it I do not get the parent (=the mainform) but instead I get the taskmanager again... I can work around that by sending some message to the mainform to put itself on top again, but I guess this would lead to too much workarounds...

It seems like the taskmanager does not show tasks but shows forms...

Anyway, thank you both for ideas.. :)

John


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Problem with Showmodal ?
« Reply #7 on: October 20, 2010, 04:27:27 pm »
From the filemanager I start the application.
From within the Mainform I  showmodal the secondform.
That works. However this form also has the X button in the top right corner.
If the user presses that button, the Secondform is hidden (I guess) and the filemanager shows up again. I really would have expected the mainform to show up.

You should never have a X minimize button in a form which will be shown as a modal form.

Read here about about to configure the form buttons:

http://wiki.lazarus.freepascal.org/Windows_CE_Development_Notes#The_Title_.22OK.22_and_.22X.22_buttons

Quote
If I just Show the form (not showmodal) the X-button works as expected.

It works normally in both cases. Just that minimizing a modal form is a very bad idea.

Quote
What is the best way to showmodal a form and be sure that the X button just closes this form?

That would be completely against the Windows CE design guidelines. It is a minimize button. Just remove the button instead as explained in the previous link.

Quote
Second: how to make sure there is only one form visible in the taskmanager (the mainform) and if activated there, to be sure that the correct form appears? I mean that IF there is a modal form open, it should NOT be visible in the taskmanager and if the application is activated again in the taskmanager, the modal form should appear, shouldn't it?

Which taskmanager? Does it exist in the emulator?

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Problem with Showmodal ?
« Reply #8 on: October 20, 2010, 05:41:02 pm »
Hi Felipe,
Quote
You should never have a X minimize button in a form which will be shown as a modal form.
No, of course not. That's why I ask to get rid of the X button. Problem is that
using   WinCEWidgetset.WinCETitlePolicy := tpOKButtonOnlyOnDialogs;
together with borderstyle:=bsDialog indeed shows an OK button, but the formsize is not adapted to the screensize (and it is floating). And to make matters worse, on a keypaddevice the menu is gone (which I need to close the form) and on PocketPC the menu that appears on the modal form is not the menu of the modal form... :(

Quote
Which taskmanager? Does it exist in the emulator?

The taskmanager is on the programs-page of WM 6.5 and is on the settings/system/Memory tab running programs on a WM 5 emulator. On WM6.1.4 it is on Settings/System/Task Manager.

With Borderstyle set to bsDialog, however, I can see now 1 running task, which is identified by the caption of mainform. Thats ok. But if the modalform is active and I switch (via Start)  to the taskmanager, I can "activate" my program. But if I do, the mainform appears (unresponsive of course) and the modalform is hidden AND unreachable...

As I said, almost anything can be worked around (except for the menus... aargh... those wince menus...)

I've tried all kinds of settings for Borderstyle, BorderIcons, autocreate or runtime create, settings for the WinCETitlePolicy, but I just can not find a combination that:
- gives me a modalform
- allows for menubuttons on that form to Cancel or Accept
- Shows the modalform instead of the Mainform if it is present AND the program is reactivated via TaskManager
- Does not allow the user to HIDE it (it would show the mainform, but ofcourse unresponsive)
- Works on both PocketPC AND Keypaddevice.....

Thanks for responding... :-) I left you some regression in the bugtracker too...  %)

John



jshand2010

  • Full Member
  • ***
  • Posts: 236
Re: Problem with Showmodal ?
« Reply #9 on: October 20, 2010, 09:21:42 pm »
As for your forms being autocreated.  there is your problem.  make sure the form you wish to load fist is auto created.  put the other for in the available forms list

from the first loaded form you enter this code:

this line below is very important:

uses paschild;  paschild is the name of the source file of the form you are wanting to load on top of your first form.  NOTE:  This does not go to the top of the source file, but just after implementation for example:

implementation

{$R *.lfm}

{ TfrmMain }

uses paschild;

Then add this code:

begin
  Application.CreateForm(Tfrmchild, frmchild);
  frmchild.ShowModal;
end;

do not use frmchild.Free as it will give you errors.

to close the form all you need to do is use this code:

frmchild.Close;

Hope this helps
« Last Edit: October 20, 2010, 10:20:03 pm by jshand2010 »
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Problem with Showmodal ?
« Reply #10 on: October 21, 2010, 05:31:10 am »
No, of course not. That's why I ask to get rid of the X button. Problem is that
using   WinCEWidgetset.WinCETitlePolicy := tpOKButtonOnlyOnDialogs;
together with borderstyle:=bsDialog indeed shows an OK button, but the formsize is not adapted to the screensize (and it is floating). And to make matters worse, on a keypaddevice the menu is gone (which I need to close the form) and on PocketPC the menu that appears on the modal form is not the menu of the modal form... :(

Yes, that's how it should work ... as documented here:

http://wiki.lazarus.freepascal.org/Windows_CE_Development_Notes#Positioning_and_size_of_Dialogs_and_Forms

What about using tpAlwaysUseOKButton or tpControlWithBorderIcons ?

Quote
The taskmanager is on the programs-page of WM 6.5 and is on the settings/system/Memory tab running programs on a WM 5 emulator. On WM6.1.4 it is on Settings/System/Task Manager.

Please open a bug report about the task manager issue.

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Problem with Showmodal ?
« Reply #11 on: October 21, 2010, 06:40:38 am »
So many possible variations in creating, showing and closing forms...

Quote
What about using tpAlwaysUseOKButton or tpControlWithBorderIcons ?

This is a setting per project, am I right? e.g. I cannot set this per form?

@jshand2010:
But where does the form get freed now? I mean, if this form is showed and closed several times, does it fill up memory?

John


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Problem with Showmodal ?
« Reply #12 on: October 21, 2010, 06:52:28 am »
This is a setting per project, am I right? e.g. I cannot set this per form?

Per project and should be done before Application.Initialize.

tpControlWithBorderIcons allows a per form selection as explained in the docs.

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Problem with Showmodal ?
« Reply #13 on: October 21, 2010, 07:02:07 am »
Felipe,

Quote
Please open a bug report about the task manager issue.

I am not sure this is a Lazarus/WinCE bug.

This TaskManager shows captions of forms, not names of programs. Same thing in Windows XP task-manager, where you need to select the running processes-tab to see the names of the executables.

Somewhere these names (form-captions and executablenames) get mixed up.
In the project-file I use:

Code: [Select]
hWnd:= Findwindow(nil, 'caption of mainform');
 if hWnd<>0
  then
   begin
    SetForeGroundWindow(hWnd);
    halt(0);
   end;
To make sure the app is "justOne".
A problem arises here (on wm5 keypaddevice at least) when the formcaption is the same name as the executable. In that case the form is not found by FindWindow and a new instance is started. If I use different names for formcaption and executable, it works ok.

Findindow is a windows API call (if I am correct), so the problem is somewhere in Windows, not in Lazarus/WinCE?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Problem with Showmodal ?
« Reply #14 on: October 21, 2010, 08:33:13 am »
Findindow is a windows API call (if I am correct), so the problem is somewhere in Windows, not in Lazarus/WinCE?

You are correct, FindWindow is a Windows API call, so the problem is not related to Lazarus.

 

TinyPortal © 2005-2018