0

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.
SOUser
  • 3,802
  • 5
  • 33
  • 63
  • possibly also : [Delphi application with login / logout - how to implement?](http://stackoverflow.com/q/7839648/327083) – J... Nov 04 '16 at 09:36
  • 1
    You are showing the form before the application is running i.e. the main message loop is not initialised yet. – Paul Michael Nov 04 '16 at 09:44
  • 1
    @J - Does the class name matter on the question you linked as a dupe? Genuine question, it's impossible to read that question. – Sertac Akyuz Nov 04 '16 at 10:04
  • @PaulMichael Many thanks for pointing out the correct way ! Nonetheless, calling `Visible := True` does not change the situation described. – SOUser Nov 04 '16 at 12:06
  • @J... I don't think my question is a duplicate. – SOUser Nov 04 '16 at 12:07
  • @SertacAkyuz Many thanks ! – SOUser Nov 04 '16 at 12:07
  • @SertacAkyuz I don't think the class name matters in this question either - at least I don't see any code showing where or how it does here. – J... Nov 04 '16 at 12:08
  • @J... It is written (clearly): `If its name does not start with "TForm", it can not be seen when Alt+Tab. `. – SOUser Nov 04 '16 at 12:16
  • @SOUser Yes, I read what you wrote, but your code does not duplicate the problem you say it does - nor does there seem to be any reason to expect it should. It would be helpful to see the actual code that doesn't work and the actual code that does work. The additional comments in the code of `WRONG` and `CORRECT` seem unrelated and confusing - why are they there? – J... Nov 04 '16 at 12:22
  • @J... Do you suggest that I provide a duplicate "uActualMainForm" with only one difference - its class name ? If you suggest I should do that, I will do it. – SOUser Nov 04 '16 at 12:24
  • @J... The code with a different class name is provided explicitly. Your suggestion of removing redundant comment is taken. The suggestion of Paul is also taken. I should say sorry because even though there is only one change of class name, there are multiple places to type the change in both .dpr and .pas. – SOUser Nov 04 '16 at 12:37
  • @SOUser I still can't replicate this. Both of these produce the expected form, on the taskbar, and visible in the `alt+tab` list (Win 7x64). Is this only a problem with Win10? – J... Nov 04 '16 at 12:54
  • @J... Cannot reproduce.... O_O Thank you for your efforts ! I will set up a Win7 in VMWare and test there. – SOUser Nov 04 '16 at 13:05
  • 1
    Your code is incorrect. It has nothing to do with the classname involved if your code that runs the app itself has a flaw. Reproduce it without hand-coding any changes in the .dpr file, by just changing the classname of the form in it's unit instead, and you have a problem. Modify the .dpr yourself, introduce erroneous code, and you can make many imaginary bugs appear. I have dozens of applications, not a single one of which has a form name starting with `TForm`, and all work properly. – Ken White Nov 04 '16 at 14:02
  • @KenWhite May I ask which part of the code is `incorrect`, `flaw`, or `erroneous` ? More over, I am really surprised at how you consider hand-coding .dpr file. – SOUser Nov 04 '16 at 14:57
  • 1
    I don't have an issue with editing the .dpr file. I have an issue with editing the .dpr file incorrectly, causing a problem, and then blaming it on a problem in the language. As far as what part is correct, you identify that in your first code snippet with the lines you have commented as CORRECT and WRONG. And your claim that *if its name does not start with "TForm*, it cannot be seen with Alt+Tab is simply wrong, as I said in my previous comment as well (and you conveniently ignored). – Ken White Nov 04 '16 at 15:15
  • @KenWhite Your comments make a lot sense to me ! Thanks for your efforts :) I should probably forget about artificial bugs. – SOUser Nov 04 '16 at 15:19
  • 1
    @SOUser What I suggest you do is to create a new, minimal, project and start this from scratch. Make your form classes normally and try to reproduce this yourself with a fresh and clean project. I expect you will not be able to. As others have said, it seems unthinkable that the compiler, or the VCL base classes, take conditional action based on the format or contents of the name given to a custom type. It feels like something else has to be wrong with your project that we can't see. – J... Nov 04 '16 at 16:25
  • @J... The code posted above is new, minimal, from scratch. Anyway, from my further tests, it seems what I observe is related to SWinClassName and Alt+Tab (at least on Win10). No more comments from me, since this is a duplicate of some other topic, from your point of view. – SOUser Nov 05 '16 at 13:57
  • 1
    The dupe closure was nonsensical but it should be closed as off topic due to not being reproducible. – David Heffernan Nov 05 '16 at 22:35

0 Answers0