Recent

Author Topic: Lazarus V1.6.2 Error on Showmodal - Form cannot focus.  (Read 3508 times)

phil_v

  • New Member
  • *
  • Posts: 12
Lazarus V1.6.2 Error on Showmodal - Form cannot focus.
« on: February 28, 2017, 05:49:44 am »
Hope you can help. Thanks in advance.
Lazarus 1.6.2
FPC 3.0.0
SVN 53354
i38s-win32-win32/win64
Windows 7 Pro 32 Bit

I have an application that opens a form with Showmodal that works fine in Lazarus V1.6.
When I upgrade to Lazarus 1.6.2 I get an error exception class 'EInvalidOperation'
message : TCustomform.SetFocus)SchedFrm.TSchedfrm Can not focus

I tried uninstall V1.6.2, and re-install V1.6, and all works OK with no error.
Then re-install v1.6.2, and error happens again.
The error occurs in customform.inc at line 2839,  before the forms OnShow event.

I don't know how to resolve the error in V1.6.2.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Lazarus V1.6.2 Error on Showmodal - Form cannot focus.
« Reply #1 on: February 28, 2017, 08:43:22 am »
AFAIK focus only works in Onactivate or when the form is visible on screen.

On Delphi site:
Quote
The location. The form's onShow event actually fires before the form
is shown, and since you cannot set focus to an invisible window your
scheme fails.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: Lazarus V1.6.2 Error on Showmodal - Form cannot focus.
« Reply #2 on: February 28, 2017, 09:56:18 am »
1. You dont need install/uninstall different versions. You can install few versions at same time.
2. Show your code.

phil_v

  • New Member
  • *
  • Posts: 12
Re: Lazarus V1.6.2 Error on Showmodal - Form cannot focus.
« Reply #3 on: March 01, 2017, 12:47:45 am »
Thanks mangakissa, FTurtle

With further tracing of the error, I found that it occurred at line 2883 in customform.inc... Code below.

Line 2883 is executed if the forms PopupMode = pmNone.
I changed the forms PopupMode to pmAuto in the IDE via Object Inspector, and the application worked OK.
Confirmed by changing the property back to pmNone, and the application created the error again.


customform.inc
...

2804 function TCustomForm.ShowModal: Integer;
...
...
2877 Application.ModalStarted;
2878  try
2879    Include(FFormState, fsModal);
2880    if PopupMode = pmNone then       <== <==
2881    begin
2882      RecreateWnd(Self);
2883      HandleNeeded;
2884    end;

 

TinyPortal © 2005-2018