给工程添加一个空unit(XXX.h和XXX.cpp),由于工程的所有的结构都定义在一个头文件(xx_Common.h)里面,添加unit 后,工程编译没有错误,但是在xxx.h添加下列代码时竟然出现了26个错误:
#include "xx_Common.h"

通过c++builder 6查看这些错语时,都指向这xx_Common.h中的前三个结构中的String 类型的字段,但是xx_Common.h还有很多其他的结构体也用String。错误码如下:

[C++ Warning] FormSnmp.cpp(138): W8012 Comparing signed and unsigned values
  [C++ Warning] FormSnmp.cpp(196): W8012 Comparing signed and unsigned values
  [C++ Warning] FormSnmp.cpp(229): W8012 Comparing signed and unsigned values
  [C++ Warning] FormSnmp.cpp(282): W8012 Comparing signed and unsigned values
  [C++ Warning] FormSnmp.cpp(532): W8012 Comparing signed and unsigned values
  [C++ Warning] FormSnmp.cpp(1025): W8012 Comparing signed and unsigned values
  [C++ Warning] FormConf.cpp(95): W8018 Assigning int to TColor
  [C++ Error] AC_Common.h(82): E2141 Declaration syntax error
  [C++ Error] AC_Common.h(86): E2303 Type name expected
  [C++ Error] AC_Common.h(86): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(87): E2303 Type name expected
  [C++ Error] AC_Common.h(87): E2238 Multiple declaration for 'VBItem::String'
  [C++ Error] AC_Common.h(86): E2344 Earlier declaration of 'VBItem::String'
  [C++ Error] AC_Common.h(87): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(94): E2303 Type name expected
  [C++ Error] AC_Common.h(94): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(105): E2303 Type name expected
  [C++ Error] AC_Common.h(105): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(107): E2303 Type name expected
  [C++ Error] AC_Common.h(107): E2238 Multiple declaration for 'TrapMsg::String'
  [C++ Error] AC_Common.h(105): E2344 Earlier declaration of 'TrapMsg::String'
  [C++ Error] AC_Common.h(107): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(108): E2303 Type name expected
  [C++ Error] AC_Common.h(108): E2238 Multiple declaration for 'TrapMsg::String'
  [C++ Error] AC_Common.h(107): E2344 Earlier declaration of 'TrapMsg::String'
  [C++ Error] AC_Common.h(108): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(113): E2303 Type name expected
  [C++ Error] AC_Common.h(113): E2238 Multiple declaration for 'TrapMsg::String'
  [C++ Error] AC_Common.h(108): E2344 Earlier declaration of 'TrapMsg::String'
  [C++ Error] AC_Common.h(113): E2139 Declaration missing ;
  [C++ Error] AC_Common.h(114): E2303 Type name expected
  [C++ Error] AC_Common.h(114): E2238 Multiple declaration for 'TrapMsg::String'
  [C++ Error] AC_Common.h(114): E2228 Too many error or warning messages

String 本身是系统定义的类

还有你是否使用
#ifndef Unit1H
#define Unit1H

#endif

之类的代码防止重复定义?

在新建的Unit
#include <vcl.h>
试试

没有使用
#ifndef Unit1H
#define Unit1H

#endif

我原计划用这个UNIT建一个新类的,所以改了自己定义的宏。

VC也要 #if  #define 的,C++类的标准定义啊

当然啊,这只是个好的习惯而以,刚加了个VCL.H后就没有错了,一般的ACL库的东西难道还需要另外引入相关头文件?

BCB使用是VCL库

当我在这个空的unit添加如下代码:
//—————————————————————————

#ifndef DISPLAY_SNMP_H
#define DISPLAY_SNMP_H
//—————————————————————————
#include <vcl.h>
#include "AC_Common.h"
#include <vector>
using namespace std;

class TDisplaySnmp
{
    //Constructor
public:
    __fastcall TDisplaySnmp(const TStringGrid &SGdsSnmp);

    //Operations
public:
    void __fastcall Display(const vector <VBItem> &vVBList,const int &nRecvCnt,int nTotalCols);

    //Attributes
protected:
    //TStringGrid *pSGdsSnmp;              //用于显示数据用的字符串表格控件

};

#endif

实现文件里面的函数全是空的,没有添加任何代码,在编译的时候出现这样的错误:
  [C++ Error] DisplaySnmp.h(18): E2293 ) expected
  [C++ Error] DisplaySnmp.h(25): E2321 Declaration does not specify a tag or an identifier
  [C++ Error] DisplaySnmp.cpp(13): E2293 ) expected

但是不使用TStringGrid的参数和变量时,就没有错误,不知道是为什么?

C++ BUILDER在帮助文档、调试、错误提示和定位方面,与VC相比,真的还有一大段的路要走啊。

#include "xx_Common.h"这个应该放在XXX.cpp里的哦

  TStringGrid要用#include  <Grids.hpp> 

加上就好了,C++BUILDER的帮助文件怎么就不清楚地说明呢,非得要去网上找才知道。谢谢各位啦。

TStringGrid represents a grid control designed to simplify the handling of strings and associated objects.

Unit

grids

这里的 grids 就是那个 hpp 头文件了,你还没有习惯而已

TForm represents a standard application window (form).
Unit
forms
也是一样需要 include <forms.hpp>

去掉VCL库

在窗体上放一个TStringGrid ,你就会发现已经自动包含了 <Grids.hpp>  。cb的提示有时候不是很明白,做多了你就会知道了。

该回复于2008-07-10 02:40:16被版主删除

该回复于2008-07-10 02:47:35被版主删除

该回复于2008-07-19 16:09:47被版主删除