Lazarus

Programming => Packages and Libraries => KOL => Topic started by: tomcmok on May 11, 2008, 07:37:04 pm

Title: KOL-CE Several Forms and Menus
Post by: tomcmok on May 11, 2008, 07:37:04 pm
Hi,

  This time a question about multiple form application and the TKOLMainMenu. I've got a Main Form with TKOLMainMenu with one item - "Exit" and I also have another form (say Form1) that user can open using a ListView item from the Main Form. Form1 has it's own TKOLMainMenu with one item as well - "Close". When this item is excecuted the code hides Form1. The strange thing is, that when Form1 disappers and we're back in the Main Form, the WinCE menu bar at the bottom still shows the "Close" item. Only when I activate some component on the Main Form (i.e. by clicking it) the menu shows correctly "Exit" item.

Any hints why it's like that?

Tomasz
Title: RE: KOL-CE Several Forms and Menus
Post by: yuriy_sydorov on May 12, 2008, 02:39:40 pm
It seems to be a bug. But I always create and destroy modal forms dynamically and there is no such problem in this case.
Title: RE: KOL-CE Several Forms and Menus
Post by: tomcmok on May 12, 2008, 05:45:39 pm
Yury,

  Well, the project is now too advanced and changing the way forms are accessed is not an option. Can you suggest some way I can programatically activate the Main Form to make the proper menu appear. I've already tried FocusControl, Active := True, Show, but no success.

Tomasz
Title: RE: KOL-CE Several Forms and Menus
Post by: yuriy_sydorov on May 12, 2008, 08:00:55 pm
I'll take a look on this problem...
Title: RE: KOL-CE Several Forms and Menus
Post by: tomcmok on May 13, 2008, 12:50:48 am
youry,

besides that problem, I've tried several ways of closing the current window. In Delphi I'd just do the following sequence: Create, Show, Close (that would trigger OnClose event which won't be triggered when I call hide) and eventually show again. In KOL-CE I've tried the below code:

      if not Assigned( AForm ) then
        NewAForm(AForm, Pointer(Applet));
      AForm.Form.Show;

      AForm.Form.Close; // The Menu bahaves correclty after that!

      AForm.Form.Show;

...and application hangs on the last show :(

why it's like that?
Title: RE: KOL-CE Several Forms and Menus
Post by: yuriy_sydorov on May 13, 2008, 11:00:56 am
Why not use ShowModal?
Title: RE: KOL-CE Several Forms and Menus
Post by: yuriy_sydorov on May 14, 2008, 11:20:59 am
When you execute Close method for a form, the form is destroyed. That's why you receive errors when trying to reuse it.
To prevent form's destruction add the following code in OnClose event handler:

Code: [Select]
 Accept:=False;
  Form.Hide;


Also you must have TKOLApplet component on your main form.
Title: RE: KOL-CE Several Forms and Menus
Post by: tomcmok on May 14, 2008, 01:47:20 pm
Well, that is strange, because it doesn't fire the OnDestroy event...?

Look - here's what I do:

1) I do the "lazy" creation of the form object and I show the form:

      if not Assigned( KontrahenciForm ) then
        NewKontrahenciForm(KontrahenciForm, Pointer(Applet));

      KontrahenciForm.Form.Show;

2) then I want to keep the form in memory and not waste time and resources for creating it again and again as it will be used many times by a user and also in a modal wersio, where the same form behaves differently (that's whay I do not want to open it always as modal)

3) When the user wants to get into the form again, the same code from 1) is executed but the form is not created again as it is supposed to be still in the device memory.

4) When I call Hide, first disadvantage is that OnClose is not fired and the second is that original problem with Menu of the paren form that is not refreshed.

I've tried the trick you suggested above it solves the problem of triggering OnClose, but the issue with Menu remains.

...and what about that form destroying - as I wrote at the top why in such case it does not fire OnDestroy?

Tomasz
Title: RE: KOL-CE Several Forms and Menus
Post by: yuriy_sydorov on May 14, 2008, 05:05:23 pm
In my tests OnDestroy is fired for a form when Close method is executed. Try to display message box in OnDestroy.
To prevent destruction you need to add a code above in OnClose event handler.
With ShowModal all works as expected, but Show does not work, because I never tested showing non modal second form. 2 non modal forms in single application is not common case for PocketPC.
Why you need 2 non-modal forms?