TFormOnHide (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses two forms, each with a label and a button. When you click a button, the other form appears and the current form disappears. Also, a message appears in the label of the form that is showing, indicating that the other form is hidden. Set the OnHide event handler for each form to FormHide.

Code

This is the implementation section of TFormOnHide.cpp:

#include "TFormOnHide.h"
#include "Unit2.h"  // You must include the header file of unit2 too.

#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}

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

void __fastcall TForm1::FormHide(TObject *Sender)
{
  Form2->Label1->Caption = "Form1 is hiding";
}


Code

This is the implementation of Unit2.cpp:

#include "Unit2.h"
#include "TFormOnHide.h"  // You must include the header file of unit1 too.

#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;

__fastcall TForm2::TForm2(TComponent* Owner)
	: TForm(Owner)
{
}

void __fastcall TForm2::Button1Click(TObject *Sender)
{
  Form1->Show();
  Hide();
}

void __fastcall TForm2::FormHide(TObject *Sender)
{
  Form1->Label1->Caption = "Form2 is hiding";
}

Uses