奇怪的问题

BSRONG 2002-07-19 12:09:57
我想动态创建窗体
代码如下
unit1.cpp
#include "Unit1.h"
#include "unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TCreateActiveForm *CreateActiveForm=new TCreateActiveForm(Application,1);
CreateActiveForm->ShowModal();
delete CreateActiveForm;
}
//-----------------------------------------------

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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//------------------------------------------------------------------------
#endif


unit2.cpp



//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)


__fastcall TCreateActiveForm::TCreateActiveForm(TComponent *Owner,int count):TForm(Owner,0)
{ Height=100;
Width=200;
Position=poScreenCenter;
Caption="动态创建窗体";
PopupMenu1=new TPopupMenu(this);
Exit1->Caption="退出";
Exit1->OnClick=OnExit1Click;
PopupMenu1->Items->Add(Exit1);
PopupMenu=PopupMenu1;
okBtn=new TButton(this);
okBtn->Parent=this;
okBtn->Top=32;
okBtn->Left=(Width-okBtn->Width)/2;
okBtn->Caption="退出";
okBtn->OnClick=okButtonClick;
}
void __fastcall TCreateActiveForm::OnExit1Click(TObject *Sender)
{ Close();
}
void __fastcall TCreateActiveForm::okButtonClick(TObject *Sender)
{
Close();
}

unit2.h

//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#endif
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>

class TCreateActiveForm: public TForm
{
private:
TButton *okBtn;
TPopupMenu *PopupMenu1;
TMenuItem *Exit1;
void __fastcall OnExit1Click(TObject *Sender);
void __fastcall okButtonClick(TObject *Sender);
public:
virtual __fastcall TCreateActiveForm(TComponent *Owner,int Count);
};

按F9运行如下
按下确定后
就不正常了,为什么?
高手指点
project1.cpp如下
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
USERES("Project1.res");
USEFORM("Unit1.cpp", Form1);
USEUNIT("Unit2.cpp");
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
//---------------------------------------------------------------------------


...全文
54 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JamesJiang 2002-07-19
  • 打赏
  • 举报
回复
__fastcall TCreateActiveForm::TCreateActiveForm(TComponent *Owner,int count):TForm(Owner,0)
这行应该有问题吧,TForm有这种形式的构造函数吗?
ChildClassName::ChildClassName(PARAM1 PARAM2):ParentClassName(PARAM1,PARAM2)的含义是强制执行指定的父类的构造函数,默认情况下是执行父类的默认构造函数,所以必须在父类中定义了ParentClassName(PARAM1,PARAM2)形式的构造函数才行。

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧