C++ Builder 程序出错处理:Error in modu
2020-07-04 本文已影响0人
玄坴
C++ Builder 参考手册 ➙ 常见的出错和异常处理 ➙ Declaration of class TForm1 is missing or incorrect
- 出错提示
- 产生原因及解决方法
1. 出错提示
出错时弹出对话框:“Error in module Unit1: Declaration of class TForm1 is missing or incorrect.”
![](https://img.haomeiwen.com/i19822773/3d10ef113474938c.png)
出错时不能编译,存盘也会弹出错误。
![](https://img.haomeiwen.com/i19822773/ae41853a4c719b83.png)
2. 产生原因及解决方法
在 .h 文件里面的窗体类里面的 __published: 区段的前面含有大括号 { 和 } 引起的,虽然语法没有错误,但是窗体设计找不到这个区段了。
例如,下面是一段出错代码:
class TForm1 : public TForm
{
public:
typedef struct { int a; } T;
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button1;
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
![](https://img.haomeiwen.com/i19822773/0b07a167c4819a8d.png)
错误原因是在窗体类里面,在 __published: 之前出现大括号 { } 引起的错误,把 __published: 之前的代码移到 __published: 之后,问题解决,修改之后的代码:
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button1;
public:
typedef struct { int a; } T;
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
![](https://img.haomeiwen.com/i19822773/af5e6e80bf4ec3c1.png)
另外一段代码,也能正常编译运行:
class TForm1 : public TForm
{
public:
typedef TNotifyEvent T;
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button1;
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
![](https://img.haomeiwen.com/i19822773/fc9abc85cea2a417.png)
问题总结:
自己在窗体类里面添加的代码,要添加在 __published: 代码区段之后,因为 __published: 里面都是窗体编辑自动维护的内容,__published: 之前的内容可能会影响窗体编辑寻找 __published: 的方法,找不到了就会出错,尽管语法都没有错误,写在后面就不会出错。
相关:
C++ Builder 参考手册 ➙ 常见的出错和异常处理 ➙ Declaration of class TForm1 is missing or incorrect