将 Delphi 设置命令转换为 C++Builder
Convert Delphi Set command to C++Builder
我正在将下面看到的 Delphi 表达式转换为 C++Builder。我的 C++Builder 代码生成错误消息 E2299。我把这个错误描述的全文放在下面。您能否建议更改我的 C++ 代码以使其正常工作。
//Delphi
TYPE
Regions = (North,South,East,West);
RegionSet = SET OF Regions;
//C++Builder
enum Regions { North, South, East, West };
typedef Set<Regions, North, West> RegionSet;
E2299 Cannot generate template specialization from 'Set'
You need to add a property to your program.
The declaration of a property specifies a name and a type, and includes at least one access specifier. The syntax of a property declaration is:
property propertyName[indexes]: type index integerConstant specifiers;
where:
propertyName is any valid identifier
[indexes] is optional and is a sequence of parameter declarations separated by semicolons
Each parameter declaration has the form identifier1, ..., identifiern: type
type must be a predefined or previously declared type identifier. That is, property declarations like property Num: 0..9 ... are invalid.
the index integerConstant clause is optional.
specifiers is a sequence of read, write, stored, default (or nodefault), and implements specifiers.
Every property declaration must have at least one read or write specifier.
编辑如下:
问题是下面看到的 typedef 无法在 C++Builder 函数中编译。我在 CheckRegion 函数中设置了 typedef。
void __fastcall TForm1::CheckRegion( bool visible ){
//C++Builder
enum Regions { North, South, East, West };
typedef Set<Regions, North, West> RegionSet;
}
解决方案是将 typedef 移动到主窗体的顶部,就在 TForm1 *Form1 下方;如下所示。
//--------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// use "typedef" here
enum RegionsCpp {NorthCpp, SouthCpp, EastCpp, WestCpp };
typedef Set<RegionsCpp, NorthCpp, WestCpp> RegionSetCpp;
//--------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
您在错误的地方使用了 typedef Set ...
。
如果您使用不是本地enum Regions
,则可以使用typedef Set <...
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
enum Regions {North, South, East, West };
// You can use "enum" here, but not "typedef Set <..."
typedef Set<Regions, North, West> RegionSet;
// next typedef is OK
typedef int NumberOfParts;
}
Delphi 你可以在这里毫无问题地使用TYPE
procedure TForm1.FormClick(Sender: TObject);
TYPE
Regions = (North, South, East, West );
RegionSet = SET OF Regions;
begin
[...]
end;
C++ Builder 以下将工作
#include <vcl.h>
#pragma hdrstop
#include "Enum.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
enum Regions {North, South, East, West };
// use "typedef" here
typedef Set<Regions, North, West> RegionSet;
// also works
// typedef System::Set<Regions, North, West> RegionSet;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
[...]
}
如果您使用全局 enum Regions
,则可以使用 typedef Set <...
#include <vcl.h>
[...]
TForm1 *Form1;
enum Regions {North, South, East, West };
[...]
//--------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
typedef Set<Regions, North, West> RegionSet;
}
我正在将下面看到的 Delphi 表达式转换为 C++Builder。我的 C++Builder 代码生成错误消息 E2299。我把这个错误描述的全文放在下面。您能否建议更改我的 C++ 代码以使其正常工作。
//Delphi
TYPE
Regions = (North,South,East,West);
RegionSet = SET OF Regions;
//C++Builder
enum Regions { North, South, East, West };
typedef Set<Regions, North, West> RegionSet;
E2299 Cannot generate template specialization from 'Set'
You need to add a property to your program.
The declaration of a property specifies a name and a type, and includes at least one access specifier. The syntax of a property declaration is:
property propertyName[indexes]: type index integerConstant specifiers;
where:
propertyName is any valid identifier
[indexes] is optional and is a sequence of parameter declarations separated by semicolons
Each parameter declaration has the form identifier1, ..., identifiern: type
type must be a predefined or previously declared type identifier. That is, property declarations like property Num: 0..9 ... are invalid.
the index integerConstant clause is optional.
specifiers is a sequence of read, write, stored, default (or nodefault), and implements specifiers.
Every property declaration must have at least one read or write specifier.
编辑如下:
问题是下面看到的 typedef 无法在 C++Builder 函数中编译。我在 CheckRegion 函数中设置了 typedef。
void __fastcall TForm1::CheckRegion( bool visible ){
//C++Builder
enum Regions { North, South, East, West };
typedef Set<Regions, North, West> RegionSet;
}
解决方案是将 typedef 移动到主窗体的顶部,就在 TForm1 *Form1 下方;如下所示。
//--------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// use "typedef" here
enum RegionsCpp {NorthCpp, SouthCpp, EastCpp, WestCpp };
typedef Set<RegionsCpp, NorthCpp, WestCpp> RegionSetCpp;
//--------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
您在错误的地方使用了 typedef Set ...
。
如果您使用不是本地enum Regions
typedef Set <...
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
enum Regions {North, South, East, West };
// You can use "enum" here, but not "typedef Set <..."
typedef Set<Regions, North, West> RegionSet;
// next typedef is OK
typedef int NumberOfParts;
}
Delphi 你可以在这里毫无问题地使用TYPE
procedure TForm1.FormClick(Sender: TObject);
TYPE
Regions = (North, South, East, West );
RegionSet = SET OF Regions;
begin
[...]
end;
C++ Builder 以下将工作
#include <vcl.h>
#pragma hdrstop
#include "Enum.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
enum Regions {North, South, East, West };
// use "typedef" here
typedef Set<Regions, North, West> RegionSet;
// also works
// typedef System::Set<Regions, North, West> RegionSet;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
[...]
}
如果您使用全局 enum Regions
typedef Set <...
#include <vcl.h>
[...]
TForm1 *Form1;
enum Regions {North, South, East, West };
[...]
//--------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
typedef Set<Regions, North, West> RegionSet;
}