注册 登录
编程论坛 C++ Builder

菜鸟!!winform程序中如何在头文件中定义函数

炫色流年 发布于 2012-08-06 20:25, 1494 次点击
我在窗体上有一个按钮,一个edit,要求按一下按钮,edit上显示出"AAA",用一个函数实现,请问在头文件中和cpp文件中应该怎么做??
函数void ShowAAA()
{
edit->text="AAA";
}

上面这段代码声明应该放在哪里,实现放在哪里??






//unit1.cpp-------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btnSunClick(TObject *Sender)
{

}
//---------------------------------------------------------------------------

//--------------------------------------------------------------------
unit1.h

class TMainForm : public TForm
{
__published:    // IDE-managed Components
        TButton *btnSun;
        TEdit *txt1;
        void __fastcall btnSunClick(TObject *Sender);
private:    // User declarations
public:        // User declarations
        __fastcall TMainForm(TComponent* Owner);

};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif



2 回复
#2
修雅2012-08-07 15:45
//unit1.cpp-------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btnSunClick(TObject *Sender)
{
    ShowAAA();

}
void TForm1::ShowAAA()
{
        Edit->Text="AAA";
}
//---------------------------------------------------------------------------

//--------------------------------------------------------------------
unit1.h

class TMainForm : public TForm
{
__published:    // IDE-managed Components
        TButton *btnSun;
        TEdit *txt1;
        void __fastcall btnSunClick(TObject *Sender);
private:    // User declarations
public:        // User declarations
        __fastcall TMainForm(TComponent* Owner);
          void ShowAAA();      

};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
// 希望对你有帮助


#3
炫色流年2012-08-14 20:18
谢了哈
1