C++Builder 程序员博客
22 Aug
不要奇怪,我确实遇到了这样的问题,编译时出错了,错误定位在TEdit *edt1;这一行。
问题描述:
因为要用到API的SHBrowseForFolder函数,所以必须在#include <vcl.h>前加入一句:#define NO_WIN32_LEAN_AND_MEAN,问题来了,当我把TEdit控件的Name属性命名为edt1或edt11、edt12后(其实是CnPack推荐改名),编译出错了:[C++ Error] Unit1.h(14): E2040 Declaration terminated incorrectly。当我把Name属性改为edtt1或其他名字时(只要不是edt*都行),编译正常通过了!运行良好!贴出代码,各位可以试试自己的BCB6:
Unit1.cpp //————————————————————————— #define NO_WIN32_LEAN_AND_MEAN //重要,目录函数需要 #include <vcl.h> #pragma hdrstop #include "Unit1.h" //————————————————————————— #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //————————————————————————— __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //—————————————————————————
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 TEdit *edt1; private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //————————————————————————— extern PACKAGE TForm1 *Form1; //————————————————————————— #endif
如果代码中,把#define NO_WIN32_LEAN_AND_MEAN去掉,TEdit命什么名字都没有错误!
怀疑是CnPack问题,卸载后问题依旧!
我的编程环境:
WINDOWS XP SP2
BCB 6 + Update 4
Indy 10.2.3
CnPack IDE专家包 Ver: 0.8.3.374 Build 2008.04.01
把#include <vcl.h> 放在 define NO_WIN32_LEAN_AND_MEAN 前面就可以了
即调整一下顺序。
会不会与什么名字起冲突了。。。
帮你顶了。。。
我测试没问题,会不会是与其它控件冲突或项目设置问题
同上