Opening a modal form from a modeless form
I need to be able to open a modal form from a modeless one. The catch
is I want it to only suspend control of the modeless form not the entire
application. I have attached three forms that are a part of a test
project.
Unit 1 is the main application form. It opens the modeless dialogs
Unit 2 is the modeless dialog. It is opened by unit 1 and opens unit 3
modal.
Unit 3 is the modal dialog. It is opened by unit 2 and only contains a
close button.
Thanks
Chris
[
Unit3.h < 1K ]
//---------------------------------------------------------------------------
#ifndef Unit3H
#define Unit3H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm3 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm3(TComponent* Owner);
//---------------------------------------------------------------------------
extern PACKAGE TForm3 *Form3;
//---------------------------------------------------------------------------
#endif
[
Unit1.dfm < 1K ]
?
TMAINFORM 0 P TPF0 TMainForm MainForm Left B Top q Width ? Height y Caption Main Color clBtnFaceFont.Charset DEFAULT_CHARSET
Font.Color clWindowText Font.Height ? Font.Name
MS Sans Serif
Font.Style OldCreateOrder
PixelsPerInch `
TextHeight
TButton Button1 Left Top Width 1 Height Q Caption Open TabOrder OnClick Button1Click
[
Unit1.h < 1K ]
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
[
Unit2.cpp 1K ]
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMyForm *MyForm;
//---------------------------------------------------------------------------
__fastcall TMyForm::TMyForm(TComponent* Owner)
: TForm(Owner)
{
//---------------------------------------------------------------------------
void __fastcall TMyForm::Button1Click(TObject *Sender)
{
Close();
//---------------------------------------------------------------------------
void __fastcall TMyForm::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
//---------------------------------------------------------------------------
void __fastcall TMyForm::CreateParams(
Controls::TCreateParams & _params )
{
TCustomForm::CreateParams( _params );
_params.WndParent = 0;
void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MessageBox(this->Handle,"This is a modal messagebox\n for a modeless dialog","MessageBoxTest",MB_OK);
//---------------------------------------------------------------------------
void TMyForm::Initialize()
{
Show();
void __fastcall TMyForm::Button3Click(TObject *Sender)
{
TForm3 *pForm = new TForm3(this);
pForm->ShowModal();
//---------------------------------------------------------------------------
[
Unit2.h 1K ]
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TMyForm : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
TButton *Button3;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TMyForm(TComponent* Owner);
virtual void __fastcall CreateParams( Controls::TCreateParams & _params );
void Initialize();
//---------------------------------------------------------------------------
extern PACKAGE TMyForm *MyForm;
//---------------------------------------------------------------------------
#endif
[
Unit3.cpp < 1K ]
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Close();
//---------------------------------------------------------------------------
[
Unit3.dfm < 1K ]
?
TFORM3 0 T TPF0 TForm3 Form3 Left Top Width ? Height G Caption Another Form Color clBtnFaceFont.Charset DEFAULT_CHARSET
Font.Color clWindowText Font.Height ? Font.Name
MS Sans Serif
Font.Style OldCreateOrder
PixelsPerInch `
TextHeight
TButton Button1 Left ( Top Width Y Height Caption &Close TabOrder OnClick Button1Click
[
Unit1.cpp < 1K ]
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
TMyForm * pForm = new TMyForm(this);
pForm->Initialize();
// pForm->Show();
//---------------------------------------------------------------------------