简体   繁体   中英

Convert Delphi Set command to C++Builder

I am converting the Delphi expression seen below to C++Builder. My C++Builder code generates the error message E2299. I put the full text for this error description below. Can you recommend a change to my C++ code to get this working.

//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.

edit below:

The problem was the typedef seen below would not compile inside a C++Builder function. I had the typedef setup in the CheckRegion function.

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; 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.

You can use typedef Set <... if you using NOT a local enum Regions

//---------------------------------------------------------------------------
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

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

C++ Builder following will work

#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

#include <vcl.h>
[...]
TForm1 *Form1;
enum Regions {North, South, East, West };
[...]
//--------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
 typedef Set<Regions, North, West> RegionSet;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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