Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Later created form always above earlier created form.


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Jan 19, 2015 9:22 AM Last Post By: jarkko halme
jarkko halme

Posts: 3
Registered: 8/17/01
Later created form always above earlier created form.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 18, 2015 7:21 AM
From some reason both of my C++Builders XE2 and XE5 have started to behave so that all the time the later created form is above the earlier created form.

See three codes below:

THE FIRST FORM CODE
#include <vcl.h>
#pragma hdrstop

#include "Unit6.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm6 *Form6;
//---------------------------------------------------------------------------
__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
}

THE SECOND FORM CODE:
#include <vcl.h>
#pragma hdrstop

#include "Unit7.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm7 *Form7;
//---------------------------------------------------------------------------
__fastcall TForm7::TForm7(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm7::FormCreate(TObject *Sender)
{
Form7->Show();
}

AND THE "MAIN":
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------

USEFORM("Unit6.cpp", Form6);
USEFORM("Unit7.cpp", Form7);
//---------------------------------------------------------------------------
WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
try
{
Application->Initialize();
Application->MainFormOnTaskBar = true;
Application->CreateForm(__classid(TForm6), &Form6);
Application->CreateForm(__classid(TForm7), &Form7);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}

If I now run the code the Form7 is always above Form6, if I click with mouse Form6, Form7 is still above Form6. Form6 becomes active bu stays below Form7. The FormStyle is in both forms fsNormal. If I change the creation order of forms 6 and 7 in the "MAIN" then Form6 always stays on the top.

Is there some general setting somewhere, which could cause this? And how it is possible that both IDEs XE2 and XE5 is doing this?

Thanks in advance.

regards
Jarkko halme

jarkko halme

Posts: 3
Registered: 8/17/01
Re: Later created form always above earlier created form.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 18, 2015 9:51 AM   in response to: jarkko halme in response to: jarkko halme
I noticed that I have to put Application->MainFormOnTaskBar = false; then it works ok.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Later created form always above earlier created form.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 18, 2015 1:24 PM   in response to: jarkko halme in response to: jarkko halme
jarkko wrote:

From some reason both of my C++Builders XE2 and XE5 have started
to behave so that all the time the later created form is above the
earlier created form.

It is supposed to be, by design. Look at the TForm::PopupMode and TForm::PopupParent
properties, they control this behavior. See my explanation in the following
discussion from earlier this week:

new windows stays on top of the other window
https://forums.embarcadero.com/thread.jspa?threadID=111705

Your TForm6 is your app's MainForm.

void __fastcall TForm7::FormCreate(TObject *Sender)
{
Form7->Show();
}

DO NOT use the OnCreate event in C++. It is a Delphi idiom that can cause
illegal behavior in C++. Use the actual TForm7 constructor instead.

Also, since you are already inside of TForm7's code, you should not be using
the global Form7 variable to access members of the TForm7 class. Use the
implicit 'this' pointer instead.

It is also not a good idea to call Show() during construction. If you want
a secondary auto-created Form to be visible when constructed, simply set
its Visible property to true at design-time, and let the DFM streaming system
handle making the Form appear.

If I now run the code the Form7 is always above Form6, if I click with
mouse Form6, Form7 is still above Form6.

As it should be, because Form6 is begin set as the implicit PopupParent for
the Form7 window, per my earlier explanation.

And how it is possible that both IDEs XE2 and XE5 is doing this?

This behavior was first introduced in Delphi 8 (there was no C++Builder 7,
8, or 2005 - the next C++Builder version released after 6 was 2006), which
predates XE2.

--
Remy Lebeau (TeamB)
jarkko halme

Posts: 3
Registered: 8/17/01
Re: Later created form always above earlier created form.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 19, 2015 9:22 AM   in response to: jarkko halme in response to: jarkko halme
ok thanks for the extra info.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02