AppModalForms (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This application shows how to work with modal forms using the Application variable. The application also uses the Screen variable to display some information about the screen in which the application runs.

Code

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  // change the application's default font to System
  Application->DefaultFont->Name = "System";

  // change the font used in displaying text in message boxes
  Screen->MessageFont->Name = "Courier";

  // change the application's popup mode to pmAuto
  Application->ModalPopupMode = pmAuto;

  // create some customized modal forms and display them
  TForm *ModalForm1 = new TForm(Form1);
  ModalForm1->Caption = "Modal Form 1";
  ModalForm1->Color = clRed;
  ModalForm1->Hint = "Close this modal form to show another";
  ModalForm1->ShowHint = True;
  ModalForm1->ShowModal();
  Application->ModalStarted();

  // add ModalForm1 as the application's popup form
  Application->AddPopupForm(ModalForm1);

  TForm *ModalForm2 = new TForm(Form1);
  ModalForm2->Caption = "Modal Form 2";
  ModalForm2->Color = clGreen;
  ModalForm2->Hint = "Close this modal form to show another";
  ModalForm2->ShowHint = True;
  ModalForm2->ShowModal();
  Application->ModalStarted();

  TForm *ModalForm3 = new TForm(Form1);
  ModalForm3->Caption = "Modal Form 3";
  ModalForm3->Color = clBlue;
  ModalForm3->Hint = "Close this modal form to show the main form";
  ModalForm3->ShowHint = True;
  ModalForm3->ShowModal();
  Application->ModalStarted();

  // show the total number of modal forms that were displayed
  ShowMessage("There were " + IntToStr(Application->ModalLevel) + " modal forms displayed");

  // remove ModalForm1 from the array of popup forms used by the application
  Application->RemovePopupForm(ModalForm1);

  // display some information about the screen in which the application runs
  ShowMessage("The number of cursors available to the application: " + IntToStr(Screen->CursorCount));
  ShowMessage("The number of currently focused forms: " + IntToStr(Screen->SaveFocusedList->Count));
}

Uses

Personal tools
Assistance