Closing the secondary form of delphi causes the main form to lose focus

When displaying the secondary form from the main form and the second form showing the third form, and then closing both forms, the main form will lose focus.

Using Delphi 2009 with XP SP3

Here are my steps to reproduce the problem:

  • Create New VCL Forms Applications
  • Drag the button into the created form
  • In the click handler, create a new TForm1 and show it

Run the program. Click the button to display the second form. Click the button on the second form to create the third form. When both new forms are closed, the main form loses focus.

This is my code in the button click event handler:

// Using Self does not change the results
with TForm1.Create (nil) do
    show;

?

+2
5

Delphi 12.0.3170.16989 ( ) 12.0.3420.21218 ( 3 4) .

, , .

+3

, , , "" .

, , , D2009 ( 3 4), 2- "" 1- "", , .

, - ...

+2

Win32 , , , . Windows , , . DestroyWindow .

, delphi vcl. , - - , .

0

( ):

with TForm1.Create(nil) do begin
  show;
  activate;
  bringtofront;
end;
0

, Delphi 2009 Windows XP SP3. , .

, :

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

:

unit Unit1;

interface

uses
  Forms, Classes, Controls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
begin
  with TForm1.Create(nil) do
    Show;
end;

end.

,

0

Source: https://habr.com/ru/post/1768428/


All Articles