0
votes

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)
{
1
Can you show an MCVE to provide context. - David Heffernan
I assume you do not have these lines in one and the same file, right? - Rudy Velthuis
Looks like a compiler error in that the error text is for Delphi E2299. The text for C++ E2299 is totally different: docwiki.embarcadero.com/RADStudio/XE8/en/… - David Heffernan
Here is the test function I am trying to compile. This generates the E2299 error. I have .PAS files in my project. This may be a conflict with some Delphi code. I did not know this error came from the Delphi compiler. void __fastcall TForm1::CheckRegion( bool visible ){ //C++Builder enum Regions { North, South, East, West }; typedef Set<Regions, North, West> RegionSet; RegionSet reg; reg = RegionSet(); if(visible==true){ //work here }else{ //work here } } - homebase
I changed the capital S in Set to lower case so it looks like this typedef set<Regions, North, West> RegionSet; This generates a different error. E2257 , expected. The compiler gives the error on this typedef line and highlights the two brackets < >. Does that help? - homebase

1 Answers

1
votes

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