Recent

Author Topic: ShowModal - Different behaviour under Windows and Linux  (Read 7432 times)

BLL

  • Sr. Member
  • ****
  • Posts: 276
ShowModal - Different behaviour under Windows and Linux
« on: October 26, 2014, 09:06:44 pm »
Hi , I am writing a program using Lazarus for my Raspberry Pi, but as using Lazarus on the Pi makes paint drying look fast, I am using Lazarus on my Windows machine and then transferring the code across. I am quite new to both pascal and linux, having used C/C++ under Windows for many years.

In this program, I have the main form and 2 other forms. I want each form to display for 5 seconds (fullscreen so only it shows) before moving on to the next. On each form, I have a button which when clicked halts sequencing and when clicked again restarts it. Under windows, all works well but on the Pi, it opens the second form and then stops unless I either close the form or click the hold button twice, when it moves on to the next and stops again.

On the main form, I have a timer set to 5000ms and its function contains:
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
if pageCount = 2 then
 pageCount := 0
else pageCount := pageCount + 1;
 case pageCount of
  0: WxForm.Close;
  1: ElecForm.ShowModal;
  2: begin
       ElecForm.Close;
       WxForm.ShowModal;
     end;
 end;
end;
The button function on each form is like this but obviously with differing form name:
procedure TMainForm.HoldBtnClick(Sender: TObject);
begin
if Timer1.Enabled = true then
 begin
  Timer1.Enabled := false;
  HoldBtn.Caption := 'Continue';
 end
else
 begin
  Timer1.Enabled := true;
  HoldBtn.Caption := 'Hold';
 end;
end;

Why the different behaviour between the two operating systems and how can I get it to work on the Pi as it does on the Windows machine?

Any help most appreciated.
Thanks

hy

  • Full Member
  • ***
  • Posts: 221
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #1 on: October 26, 2014, 10:10:16 pm »
Didn't test it but give it a try:
Use method Hide instead of close.
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #2 on: October 27, 2014, 08:37:14 pm »
Hi

Thanks for that but it doesn't change the behaviour at all!

Brian

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #3 on: October 28, 2014, 12:57:34 am »
I'm not seeing any reason why the functionality is different between the two OS's, but I also don't think you've posted enough code for a full assessment to be made.

If you've a windows box, you may want to install a linux virtual pc.  That may speed up testing under a linux environment.  (I've not used Pi's, so don't know if there's anyway to speed up Lazarus on them)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #4 on: October 28, 2014, 09:53:20 pm »
Thanks for the repy. I don't see that any more code uploaded would help. All there is is 3 forms, one main and 2 others, caalled in sequence. ShowModal is clearly NOT behaving the same with the same source code on different operating systems. I don't see much advantage of linux in whatever form on the PC - the problem is the slowness of the RasPi which makes development slow on it. That's not surprising as it isn't intended to be a quick machine.

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #5 on: October 30, 2014, 07:59:27 pm »
Hi all
I am now even more confused over ShowModal with pascal! On Lazarus under Windows, both Show and ShowModal allow my forms to sequence and Show also allows a button on the shown form to be clicked!
My experience in C++ was that only if a form was the modal form would it respond to user input, but this doesn't seem to be the case with freePascal.
Under linux, forms will sequence only with Show and NOT with ShowModal!!
Can anyone shed some definitive info on this please?
Thanks

sam707

  • Guest
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #6 on: October 30, 2014, 08:07:03 pm »
 case somevar of
  0: some code to do;
      exit; // the case block
  1: some code to do;
      exit;
  2: .... etc etc.. etc

  end; // of case block

what does showmodal do ?

1) show the form
2) increments an internal counter (a showmodal can be called within a modal state)
3) call application.messageloop (which then knows the modal state because of the internal counter)
4) store modalresult on actions (btn pressed or programmatically)
5) exiting upon these actions or form closed by system (mouse click on system close)
6) decrements internal counter
7) return the modalresult

the "behaviour" is the same, any LCL platform

I spent hours to debug step by step 2 years ago
« Last Edit: October 30, 2014, 08:46:19 pm by sam707 »

sam707

  • Guest
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #7 on: October 30, 2014, 08:43:17 pm »
design a form put 2 buttons on it

give these 2 button a modalresult (mrOk, mrCancel) >> look at the object inspector and fill the values of ModalResult each button

now showmodal your form, clicking one of the buttons will close it and end the modalstate of the application

show the same form normally .. clicking the buttons won't close the form

the internal counter i was talking about let

1) the application know that it runs in modal state
2) only dispatch the mouse and keyboard events to the topmost modal form

due to what i explained , every form descendant in lazarus has the ability to go modal, whatever its 'borders' OSDependant design :)

(borderStye in not managing the behaviour, just the look)
« Last Edit: October 30, 2014, 09:55:50 pm by sam707 »

sam707

  • Guest
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #8 on: October 30, 2014, 08:53:45 pm »
Lazarus forms designs depend on Lazarus resources

C forms designs depend on OS resources or other Frameworks (Qt, wxWidgets, etc...)

... and the winner is... Lazarus :D integration is perfect, no need 3rd party frmwork

that may explains why u got  confused... because in C 'basic' world the rc resources editor is used to make dialogs (modal boxes) and the flags inside these resources are meaningful
« Last Edit: October 31, 2014, 04:40:38 am by sam707 »

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #9 on: October 31, 2014, 10:19:31 am »
Hi

Thanks to the repliers. What I still don't follow is why a form which has been made visible using Show, so isn't the modal form, still accepts mouse clicks to its buttons, which is what is hapening in Lazars on both linux and Windows.

My experience in C++ was that only windows made visible by showModal accepted user input, so if you just used show, the form would appear but clicking buttons did absolutely nothing. This seems logical, otherwise, show and showmodal seem to be duplicates of each other.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #10 on: October 31, 2014, 11:51:09 am »
You misunderstand the purpose of ShowModal in the VCL/LCL.
It is designed to control the closing (or not closing) of the modal window, and to restrict user interaction only to the modal window. Non-modal forms (windows) do not restrict acceptance of user keystrokes (or mouse interaction) in any way once they have the focus.
« Last Edit: October 31, 2014, 11:54:10 am by howardpc »

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: ShowModal - Different behaviour under Windows and Linux
« Reply #11 on: October 31, 2014, 09:26:46 pm »
Ah
Thanks for that - now I follow!!

 

TinyPortal © 2005-2018