2

I use Delphi XE6 : I create a TaskBarButton in my TaskBar. This button is linked on an action who make :

TForm2.Create(nil).ShowModal;

The Form2 is showing without focus. And sometimes, with a complex form, the new form appears behind the application and i have to click anywhere for see it.

Why I haven't focus on the new form created by my taskbutton ? (if I click on a simple button, my new form have focus).

Code in my MainForm :

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Unit2, System.Actions, Vcl.ActnList,
  System.Win.TaskbarCore, Vcl.Taskbar;

type
  TForm1 = class(TForm)
    ActionList1: TActionList;
    Action1: TAction;
    Taskbar1: TTaskbar;
    procedure Action1Execute(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Action1Execute(Sender: TObject);
var
   FormTest : TForm2;
begin
   try
      //self.Enabled := False;
      FormTest := TForm2.Create(nil);
      FormTest.ShowModal;
   finally
      FormTest.Free;
      //self.Enabled := True;
   end;
end;

end.

TForm2 is just a new form with component.

yNG
  • 21
  • 2
  • Questions typically contain at least one question mark somewhere. Please read ["How do I ask a good question?"](http://stackoverflow.com/help/how-to-ask) – Scott Solmer Sep 10 '14 at 14:39
  • Exactly, I have edited. Thanks – yNG Sep 10 '14 at 14:45
  • 3
    See [Form is hidden behind other forms when ShowModal is called](http://stackoverflow.com/q/1639125/576719). – LU RD Sep 10 '14 at 14:47
  • You leaked that form. If you showed a complete program that would help. – David Heffernan Sep 10 '14 at 14:50
  • 1
    @DavidHeffernan, it's possible to set `caFree` in the close event, so a leak is not definite here, but a possibility. Agreed that without code it's difficult to say. At least the single line for creating and calling showmodal looks dubious. – LU RD Sep 10 '14 at 14:56
  • @LU-RD : Thank's for this link, but when I click on a simple button, it's OK. It's when I use TTaskBar and TTaskButton that I have this problem. – yNG Sep 10 '14 at 15:02
  • 1
    @yNG Why won't you show us something that we can run to reproduce the problem? – David Heffernan Sep 10 '14 at 15:05
  • @DavidHeffernan : I have just edited for add my Unit1.pas. Is there a solution for upload a project on stackoverflow ? – yNG Sep 10 '14 at 15:09
  • The most important in that post, I think, It's a fire action with the an item of "TTaskbar". – Joc02 Sep 10 '14 at 15:10
  • Which Delphi version? – David Heffernan Sep 10 '14 at 15:12
  • I Use Delphi XE6 (it's a new VCL component Delphi XE6). – yNG Sep 10 '14 at 15:14
  • I can't reproduce this with XE6 on Windows 7 64 bit platform. – LU RD Sep 10 '14 at 15:35
  • 3
    Your `Try..Finally` block is wrong. The `Form2.Create` should come before the `Try`. Not that's the problem, merely an observation. – Andy_D Sep 10 '14 at 15:53
  • @Andy_D: Which the compiler would have explained if hints and warnings were enabled (and the poster was actually reading them). – Ken White Sep 10 '14 at 21:51

0 Answers0