C++ Builder

La Isla Bonita



Calling an Event Handler from another
Calling an Event Handler from another


Description

This example shows how to call an event handler from another event handler. Form1 contains a Panel an a Button.

EventHandler.h

#ifndef EventHandlerH
#define EventHandlerH
//---------------------------------------------------------------------------
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TButton *Button1;
	TPanel *Panel1;
	void __fastcall Button1Click(TObject *Sender);
	
	void __fastcall Panel1MouseDown(TObject *Sender, TMouseButton Button,
	TShiftState Shift, int X, int Y);
private:	// User declarations
    int pri_X;
    int pri_Y;
    TMouseButton pri_Button;
    TShiftState pri_Shift;

public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

EventHandler.cpp

#include 
#pragma hdrstop

#include "EventHandler.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//
    Panel1MouseDown( Sender, pri_Button, pri_Shift, pri_X, pri_Y);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Panel1MouseDown( TObject *Sender, TMouseButton Button,
	                                     TShiftState Shift, int X, int Y)
{
//
    pri_X = X;
    pri_Y = Y;
    pri_Button = Button;
    pri_Shift  = Shift;

    ShowMessage("Mouse Down on Panel1 \n"
                 + String("X = ")  + String(pri_X)
                 + String(" Y = ") + String(pri_Y) + "\n" +
                 + "Button =" + String(Button) );

}
<\pre>
//---------------------------------------------------------------------------     
     


Homepage

Copyright © 1997-2002 Rodolfo A. Frino. All rights reserved.