锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
enum TCloseAction { caNone, caHide, caFree, caMinimize };
typedef void __fastcall (__closure *TCloseEvent)(System::TObject* Sender, TCloseAction &Action);
__property TCloseEvent OnClose = {read=FOnClose, write=FOnClose, stored=IsForm};
Description
Use OnClose to perform special processing when the form closes. The OnClose event specifies which event handler to call when a form is about to close. The handler specified by OnClose might, for example, test to make sure all fields in a data-entry form have valid contents before allowing the form to close.
A form is closed by the Close method or when the user chooses Close from the form's system menu.
The TCloseEvent type points to a method that handles the closing of a form. The value of the Action parameter determines if the form actually closes. These are the possible values of Action:
Value Meaning
caNone The form is not allowed to close, so nothing happens.
caHide The form is not closed, but just hidden. Your application can still access a hidden form.
caFree The form is closed and all allocated memory for the form is freed.
caMinimize The form is minimized, rather than closed. This is the default action for MDI child forms.
If a form is an MDI child form, and its BorderIcons property is biMinimize, then the default Action is caMinimize. If a MDI child form does not have these settings, the default Action is caNone, meaning that nothing happens when the user attempts to close the form.
If a form is an SDI child form, Action defaults to caHide.
To close the form and free it in an OnClose event, set Action to caFree.
Note: When the application shuts down, the main form receives an OnClose event, but any child forms do not receive the OnClose event.
]]>
Main.cpp:
//Borland C++Builder
//Copyright (c) 1987, 1998-2002 Borland International Inc. All Rights Reserved.
//----------------------------------------------------------------------------
//-------------------------------------------------------------------------
// minicomp.cpp - uses the TCounter example component
//-------------------------------------------------------------------------
#include "minicomp.h"
#include <stdio.h>
#include <stdlib.h>
#include <condefs.h>
//-------------------------------------------------------------------------
USEUNIT("counter.cpp");
//---------------------------------------------------------------------------
main()
{
TExample example;
return 0;
}
//-------------------------------------------------------------------------
TExample::TExample()
{
TCounter Counter(7);
int i;
//鎶婃帶浠禖ounter鐨勬帴鍙Multiple鍜屽閮ㄥ疄鐜癕ultipleReached榪炴帴涓?/span>
Counter.OnMultiple = MultipleReached;
for (i=0; i < 100; i++)
Counter.Increment();
}
//-------------------------------------------------------------------------
void TExample::MultipleReached(TCounter *Sender)
{
printf("Multiple=%d reached with val=%d\n", Sender->Multiple, Sender->Val);
}
//-------------------------------------------------------------------------
minicomp.h:
// minicomp.h - uses the TCounter example component
//-------------------------------------------------------------------------
#include "counter.h"
//-------------------------------------------------------------------------
class TExample
{
private:
void MultipleReached(TCounter *Sender);
public:
TExample();
};
//-------------------------------------------------------------------------
counter.h:
// counter.h. - example of a small, non-visual counter component
//-------------------------------------------------------------------------
class TCounter; // forward
typedef void (__closure *TCounterEvent)(TCounter *Sender);
//-------------------------------------------------------------------------
class TCounter
{
private:
TCounterEvent FOnMultiple; //榪欏氨鏄釜鍑芥暟鎺ュ彛
int FVal;
int FMultiple;
public:
__property int Val = {read=FVal, write=FVal};
__property int Multiple = {read=FMultiple};
__property TCounterEvent OnMultiple = {read=FOnMultiple, write=FOnMultiple};
void Clear();
void Increment();
TCounter(int Multiple);
};
//-------------------------------------------------------------------------
counter.cpp:
// counter.cpp - example of a small, non-visual counter component
//-------------------------------------------------------------------------
#include "counter.h"
//-------------------------------------------------------------------------
TCounter::TCounter(int Multiple)
{
FMultiple = Multiple;
}
//-------------------------------------------------------------------------
void TCounter::Clear()
{
FVal = 0;
}
//-------------------------------------------------------------------------
void TCounter::Increment()
{
//榪欏彞鎵ц鏃墮兘鏄閮ㄦ潵璋冪敤鐨?姝ゆ椂OnMultiple宸茬粡鍜屽闈㈤偅涓嚱鏁版帴鍙h繛鎺ヤ笂浜?br> //涔熷氨鏄皟鐢ㄧ殑鍏跺疄鏄闈㈣繘鏉ョ殑閭d釜鍑芥暟,鎶妕his浼犲嚭鍘?璁╁閮ㄩ偅涓嚱鏁版搷浣?br> //TExample::MultipleReached(this)
if (((++FVal) % FMultiple) == 0)
OnMultiple(this);
}
//-------------------------------------------------------------------------
]]>
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1); //璋冪敤榪欎釜vcl妯″潡,璇﹁Unit1.cpp
//---------------------------------------------------------------------------
//榪欓噷寰堟悶絎?娌$粰鍙傛暟鍚嶉噸鍐?涓嶇煡閬撹繖鏍峰嚱鏁伴噷闈㈣兘涓嶈兘鐢ㄥ埌榪欏嚑涓弬鏁?img src="http://www.shnenglu.com/Images/dot.gif">
//涓嶈繃濂藉儚涔熷氨娌$敤
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
//The owner of the new form is the Application object
//__classid榪斿洖涓涓寚鍚慣Form1鐨剉table鐨勬寚閽?榪欑偣榪樿鍐嶇湅鐪嬪疄鐜拌繃紼?/span>
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch ()
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
Unit1.h:
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
//閮藉彧鏄簺澹版槑閮ㄥ垎,鎵浠ュ寘鍚湪澶存枃浠墮噷闈?/span>
#include <Classes.hpp> //TPersistent, TComponent
#include <Controls.hpp> //TControl, TWinControl
#include <StdCtrls.hpp> //TButton
#include <Forms.hpp> //TApplication, TForm
//---------------------------------------------------------------------------
/*
TObject(RTTI,鍨冨溇鍥炴敹絳夋渶鍩烘湰鐨?
|
|--TList(stores an array of pointers)
|
|--TStream(read and write to some media)
| |
| |--TFileStream,TStringStream,TWinSocketStrem
|
|--TFiler(璇誨啓鎺т歡[objects]灞炴?姣斿淇濆瓨dfm鏂囦歡淇℃伅,鍦ㄥ唴瀛樹腑鏆傚瓨鎺т歡淇℃伅絳?
| |
| |--TReader
| |--TWriter(鍏蜂綋瀹炵幇Filer鍔熻兘)
|
|--TPersistent(have assignment and streaming capabilities)
|
|--TStrings(for objects that represent a list of strings)
| |
| |--TStringList(鍏蜂綋瀹炵幇)
|
|--TComponent(鎺т歡鐖剁被,鍖呮嫭鍙樉紺哄拰涓嶅彲鏄劇ず)
|
|--TApplication(鎶借薄WindowsGUI鐜,娑堟伅鏈哄埗褰撶劧榪樻湁閽堝web鐨勭幆澧?
|
|--TControl(鍙鎺т歡)
|
|--TWinControl(閽堝Windows鐨勫彲瑙嗘帶浠?
|
|--TButtonControl(Button鐨勬娊璞?
| |
| |--TButton(Button鐨勫叿浣撳疄鐜?
|
|--TScrollingWinControl(鏀寔婊氬姩鏉$殑Windows鎺т歡)
|
|--TCustomForm
|
|--TForm
*/
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner); //Owner鏄垱閫犺?Parent鏄憟鐜拌?鍙浜庡彲瑙嗘帶浠?
};
//---------------------------------------------------------------------------
/*
鎶婅繖涓獀cl(Form1)瀵煎嚭,鍏朵粬妯″潡浣跨敤榪欎釜澶存枃浠舵椂灝卞憡璇夌紪璇戝櫒,榪欎釜vcl鍦ㄥ埆澶勫叿浣撳畾涔?br>*/
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp:
#include <vcl.h>
#pragma hdrstop //涔嬪墠鐨勫ご鏂囦歡鍙互浣跨敤澶存枃浠剁紦瀛樻妧鏈?鍏朵粬鍖呭惈vcl.h鐨勭紪璇戝潡灝辯紪璇戜竴嬈?/span>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
/*
榪欓噷鐨勭枒闂湪浜?澶存枃浠墮噷闈㈠凡緇忔湁涓涓猠xtern鐨勬寚閽?榪欓噷涓轟綍榪樿鍐嶆鎼炲嚭涓寚閽?
娉ㄦ剰鍦≒roject1.cpp閲岄潰鏈変釜USEFORM鐨勫畯,榪欎釜瀹忕殑鍏蜂綋瀹氫箟鍦╲cl\sysclass.h鏂囦歡涓?br>濡備笅:
#ifdef BCBVER1
#define USEFORM(FileName, FormName) \
class DELPHICLASS T##FormName; \
extern T##FormName *FormName;
#else
#define USEFORM(FileName, FormName) \
class DELPHICLASS T##FormName; \
extern PACKAGE T##FormName *FormName;
#endif
鍙互鐪嬪嚭榪欓噷FileName鏍規湰娌$敤涓?鎵浠?鏃㈢劧緇欎簡cpp涔熷氨緇欎簡.h涔熷氨緇欎簡閭d釜extern鎸囬拡"
鐨勬兂娉曟槸閿欒鐨?cpp鏂囦歡鏍規湰灝辨病鏈夎搗鍒頒換浣曚綔鐢?榪樻槸瀹屽叏渚濊禆榪炴帴鏃墮潬extern鐨勫瓨鍌?br>灞炴у湪obj閲岄潰鍘繪壘.榪欎篃灝辨槸涓轟粈涔坈pp閲岄潰濡傛灉娌℃湁涓嬮潰榪欎釜鎸囬拡澹版槑,鎶ラ敊鐨勪笉鏄疷nit1
鑰屾槸Project1,鍥犱負鏄湪Project1璋冪敤浜嗚繖涔堜釜娌℃湁瀹氫箟涓寚閽?榪樻湁涓鐐瑰氨鏄?涔嬫墍浠ヤ細榪?br>鏍鋒槸鍥犱負.h鏄笉浼氱紪璇戠殑,Project1鍦║nit1.cpp瀵瑰簲鐨刼bj閲岄潰鍘繪壘,褰撶劧鎵句笉鍒?鎵浠ヨ繖閲?br>蹇呴』瑕佸啀嬈″啓涓婁竴鍙?
*/
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
]]>