简体   繁体   English

将Delphi Set命令转换为C ++ Builder

[英]Convert Delphi Set command to C++Builder

I am converting the Delphi expression seen below to C++Builder. 我将下面看到的Delphi表达式转换为C ++ Builder。 My C++Builder code generates the error message E2299. 我的C ++ Builder代码生成错误消息E2299。 I put the full text for this error description below. 我在下面放置了此错误描述的全文。 Can you recommend a change to my C++ code to get this working. 您能否建议对我的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' E2299无法从“设置”生成模板专业化

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; property propertyName [indexes]:类型索引integerConstant说明符;

where: 哪里:

propertyName is any valid identifier propertyName是任何有效的标识符

[indexes] is optional and is a sequence of parameter declarations separated by semicolons [indexes]是可选的,是由分号分隔的一系列参数声明

Each parameter declaration has the form identifier1, ..., identifiern: type 每个参数声明的形式为identifier1,...,identifiern:type

type must be a predefined or previously declared type identifier. type必须是预定义或预先声明的类型标识符。 That is, property declarations like property Num: 0..9 ... are invalid. 也就是说,属性声明(如属性Num:0..9 ...)无效。

the index integerConstant clause is optional. index integerConstant子句是可选的。

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. 每个属性声明必须至少具有一个读或写说明符。

edit below: 在下面编辑:

The problem was the typedef seen below would not compile inside a C++Builder function. 问题是下面看到的typedef无法在C ++ Builder函数内编译。 I had the typedef setup in the CheckRegion function. 我在CheckRegion函数中设置了typedef。

void __fastcall TForm1::CheckRegion( bool visible ){ 
//C++Builder 
enum Regions { North, South, East, West }; 
typedef Set<Regions, North, West> RegionSet; 
}    

The solution was to move the typedef to the top of the main form just below TForm1 *Form1; 解决方法是将typedef移到TForm1 * Form1下方的主窗体顶部。 like seen below. 如下所示。

//--------------------------------------
#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)
{

You are using the typedef Set ... at the wrong place. 您在错误的地方使用了typedef Set ...

You can use typedef Set <... if you using NOT a local enum Regions 如果使用本地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 you can use TYPE here without problems 德尔福,你可以在这里使用TYPE

procedure TForm1.FormClick(Sender: TObject);
TYPE
 Regions = (North, South, East, West );
 RegionSet = SET OF Regions;
begin
 [...]
end;

C++ Builder following will work 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)
{
  [...]
}

You can use typedef Set <... if you using a global enum Regions 如果使用全局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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM