Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rex X close button (top right on form) does something funny ?

1 view
Skip to first unread message

Peter

unread,
Dec 2, 2005, 8:38:54 AM12/2/05
to
Hi,

I have this strange problem,
condensed to the essence with test forms it's this,

A subform, *not* auto created, but created like this :
MyForm=new TForm2(Application);

And a couple of radio buttons on this form of which I want one to always be
checked.
Which is done is the OnShow() of that Form (see example below)
But also tried setting before the Form2->ShowModal() call with same result.

The form has two TButtons, with a ModalResult value (Ok and Cancel)
When these buttons are clicked all works normally.

However, when the red X close button on the top right of the form is clicked
the form closed normally etc.
BUT :
RadioButton2->Checked=true;
has no effect anymore.
The form shows modally the next time, yet the last checked RadioButton stays
checked, independantly from what the code is trying to do during OnShow() or
even before ShowModal()

A workaround seems to be to detroy the form pointer after being shown
modally, and create it again next time the dialog needs to be shown.
I was hoping to only have to create it once.
In any event, something is not right (I think ?) or has somebody an
explanation or feedback ?

PS. Using BCB5 but also confirmed on a BCB6 system
With or *without* T.L. XP-look (ThemeManager) component.


Main Form :

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "TestUnit1.h"
#include "TestUnit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
MyForm->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
MyForm=new TForm2(Application);
}
//---------------------------------------------------------------------------

Sub Form :

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TestUnit2.h"
#include "TestUnit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::CloseButton1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{
RadioButton2->Checked=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Form1->Caption="Close";
}
//---------------------------------------------------------------------------


Steve Aletto

unread,
Dec 2, 2005, 9:33:10 AM12/2/05
to
> A workaround seems to be to detroy the form pointer after
> being shown modally, and create it again next time the dialog
> needs to be shown.
> I was hoping to only have to create it once.

Another workaround is to call SetFocus:

void __fastcall TForm2::FormShow(TObject *Sender)
{
RadioButton2->Checked = true;

RadioButton2->SetFocus();
}

Or put an editbox on the second form as well...

The reason is not clear, though. Maybe it depends on how the VCL
handles the messages behind the scenes. By the way, do not use
Form::OnCreate and Form::OnDestroy events.

Steve.


Hans Galema

unread,
Dec 2, 2005, 9:23:49 AM12/2/05
to
Peter wrote:

> However, when the red X close button on the top right of the form is clicked
> the form closed normally etc.
> BUT :
> RadioButton2->Checked=true;
> has no effect anymore.

> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> MyForm->Show();
> }

You are speaking of a modal form but you show here code for a non modal
form. Anyhow your problem has nothing to do with modal. Could
reproduce it with just three radiobuttons on the second form.

void __fastcall TForm1::Button1Click(TObject *Sender)
{

MyForm->RadioButton2->Checked = true;
MyForm->Show();
}

This does not work, where the following code does its job:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
MyForm->Show();

MyForm->RadioButton2->Checked = true;
}

> void __fastcall TForm1::FormCreate(TObject *Sender)
> {

// do not use FormCreate. Put this code in the constructor instead.
> MyForm=new TForm2(Application);
> }

Don't know why the VCL behaves like that.

Hans.

Peter

unread,
Dec 2, 2005, 3:25:04 PM12/2/05
to
> You are speaking of a modal form but you show here code for a non modal
> form.

Yes, sorry about that,
I had tried it with ShowModal() using BCB 5 but apparently my colleague
(who's example code I used to post) used Show() on his BCB 6 version.


Peter

unread,
Dec 3, 2005, 6:45:49 AM12/3/05
to
> Don't know why the VCL behaves like that.

Seems like a bug to me.


0 new messages