In the VCL Forms application below, the Application.MainForm is hidden and another TForm descendant is shown instead. The strange thing is that only if the name of this TForm descendant starts with "TForm", it can be seen when Alt+Tab is pressed. If its name does not start with "TForm", it can not be seen when Alt+Tab. The above is tested with Delphi XE-Berlin on Windows 10 Ann Edition x64.
Could you help to comment the reason why the class name matters here ? O_O
More over, does the class name of the TForm descendant matters somewhere else ?
program
program Strange;
uses
Forms,
uHiddenMainForm in 'uHiddenMainForm.pas' {HiddenMainForm},
uActualMainForm in 'uActualMainForm.pas' {FormActualMainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(THiddenMainForm, HiddenMainForm); // Note: WRONG ! Still, interesting strangeness.
Application.ShowMainForm := False;
Application.MainFormOnTaskbar := True;
// Application.CreateForm(THiddenMainForm, HiddenMainForm); // Note: CORRECT
with TFormActualMainForm.Create(HiddenMainForm) do
begin
Show;
Update;
end;
Application.Run;
end.
unit for the main form (i.e., Application.MainForm)
unit uHiddenMainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
THiddenMainForm = class(TForm)
end;
var
HiddenMainForm: THiddenMainForm;
implementation
{$R *.dfm}
end.
unit for the actual "main" form
unit uActualMainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
TFormActualMainForm = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
protected
procedure CreateParams(var Params: TCreateParams) ; override;
end;
implementation
{$R *.dfm}
{ TFormActualMainForm }
procedure TFormActualMainForm.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;
procedure TFormActualMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;
end;
end.
The problem If its name does not start with "TForm", it can not be seen when Alt+Tab.
shows itself with the following code. The only difference is the change of class name from TFormActualMainForm to TXFormActualMainForm.
program
program Strange;
uses
Forms,
uHiddenMainForm in 'uHiddenMainForm.pas' {HiddenMainForm},
uActualMainForm in 'uActualMainForm.pas' {XFormActualMainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(THiddenMainForm, HiddenMainForm);
Application.ShowMainForm := False;
Application.MainFormOnTaskbar := True;
with TXFormActualMainForm.Create(HiddenMainForm) do
begin
Visible := True;
end;
Application.Run;
end.
unit for the actual "main" form
unit uActualMainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
TXFormActualMainForm = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
protected
procedure CreateParams(var Params: TCreateParams) ; override;
end;
implementation
{$R *.dfm}
{ TXFormActualMainForm }
procedure TXFormActualMainForm.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;
procedure TXFormActualMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;
end;
end.