Board index » cppbuilder » Syntax errors - simple component

Syntax errors - simple component


2003-11-21 05:58:46 PM
cppbuilder26
I want to install a StringGrid decendant to the pallette but I'm
getting compile errors. May I have some help please?
I have no clue what to do with this error
[C++ Error] MGrid.cpp(21): E2188 Expression syntax
I presume that all I need to do is add a semicolon but I don't
understand this error
[C++ Error] MGrid.cpp(35): E2379 Statement missing ;
//--------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MGrid.h"
#pragma package(smart_init)
//--------------------------------------------------------------
static inline void ValidCtrCheck(TMGrid *)
{
new TMGrid(NULL);
}
//--------------------------------------------------------------
__fastcall TMGrid::TMGrid(TComponent* Owner) : TStringGrid(Owner)
{
public: //<<<<<<<<<<-------- line 21
void __fastcall MoveRow( int FromIndex, int ToIndex )
{
inherited::MoveRow( FromIndex, ToIndex );
}
void __fastcall InsertRow( int Index )
{
++RowCount;
inherited::MoveRow( RowCount - 1, Index );
}
void __fastcall DeleteRow( int Index )
{
inherited::DeleteRow( Index );
}
} // <<<<<<<<<<<<<------------- line 35
//--------------------------------------------------------------
namespace Mgrid
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMGrid)};
RegisterComponents("IDEAtum", classes, 0);
}
}
//--------------------------------------------------------------
#ifndef MGridH
#define MGridH
//--------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <Grids.hpp>
//--------------------------------------------------------------
class PACKAGE TMGrid : public TStringGrid
{
private:
protected:
public:
__fastcall TMGrid(TComponent* Owner);
__published:
};
//--------------------------------------------------------------
#endif
 
 

Re:Syntax errors - simple component

Quote
I have no clue what to do with this error

[C++ Error] MGrid.cpp(21): E2188 Expression syntax
>//--------------------------------------------------------------
__fastcall TMGrid::TMGrid(TComponent* Owner) : TStringGrid(Owner)
{
public: //<<<<<<<<<<-------- line 21
void __fastcall MoveRow( int FromIndex, int ToIndex )
{
inherited::MoveRow( FromIndex, ToIndex );
}
} // <<<<<<<<<<<<<------------- line 35
//--------------------------------------------------------------
.............>_<
"public" never occur in function.
use for "class" declare only.
 

Re:Syntax errors - simple component

On 21 Nov 2003 02:58:46 -0700, JD wrote:
Quote
public: //<<<<<<<<<<-------- line 21
Shouldn't appear in a function.
--
liz
 

{smallsort}

Re:Syntax errors - simple component

"JD" < XXXX@XXXXX.COM >wrote in message
Apparently you're trying to expose a MoveRow method by creating a
descendant of TStringGrid. If you want to use the word inherited in
CPB, you have to write a typedef for it. For authors not coming from
Delphi, it's more common just to write the name of the class. But you
could write your code like this. Note in each case that most of the
lines were written by the IDE:
Header:
typedef TCustomGrid inherited;
class PACKAGE TMGrid : public TStringGrid
{
private:
protected:
public:
__fastcall TMGrid(TComponent* Owner);
void __fastcall MoveRow( int FromIndex, int ToIndex );
__published:
};
Code File:
__fastcall TMGrid::TMGrid(TComponent* Owner)
: TStringGrid(Owner)
{
}
void __fastcall TMGrid::MoveRow( int FromIndex, int ToIndex )
{
inherited::MoveRow( FromIndex, ToIndex );
}
 

Re:Syntax errors - simple component

"Timothy H. Buchman" <tbuchmanREMOVE(at)PLEASEcitycenter D O To r g>a écrit
dans le message de news: XXXX@XXXXX.COM ...
Quote
"JD" < XXXX@XXXXX.COM >wrote in message
news:3fbdefe6$ XXXX@XXXXX.COM ...

Apparently you're trying to expose a MoveRow method by creating a
descendant of TStringGrid. If you want to use the word inherited in
CPB, you have to write a typedef for it. For authors not coming from
Delphi, it's more common just to write the name of the class. But you
could write your code like this. Note in each case that most of the
lines were written by the IDE:

Header:
typedef TCustomGrid inherited;
class PACKAGE TMGrid : public TStringGrid
{
private:
protected:
public:
__fastcall TMGrid(TComponent* Owner);
void __fastcall MoveRow( int FromIndex, int ToIndex );
__published:
};


Code File:
__fastcall TMGrid::TMGrid(TComponent* Owner)
: TStringGrid(Owner)
{
}
void __fastcall TMGrid::MoveRow( int FromIndex, int ToIndex )
{
inherited::MoveRow( FromIndex, ToIndex );
}

It will be better to put the typedef inside the class.
Doing this will allow you to redefine inherited in other files without
conflicts....
 

Re:Syntax errors - simple component

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
I want to install a StringGrid decendant to the pallette but
I'm getting compile errors. May I have some help please?
You are trying to declare functions inside of other functions. You can't do
that. You are supposed to declare your new methods in the header file and
them implement them separately in the .cpp file. Do not try to do
everything inside the constructor code. For example:
--- MGrid.h ---
#ifndef MGridH
#define MGridH
//--------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <Grids.hpp>
//--------------------------------------------------------------
class PACKAGE TMGrid : public TStringGrid
{
typedef TStringGrid inherited;
private:
protected:
public:
__fastcall TMGrid(TComponent* Owner);
void __fastcall MoveRow( int FromIndex, int ToIndex );
void __fastcall InsertRow( int Index );
void __fastcall DeleteRow( int Index );
__published:
};
//--------------------------------------------------------------
#endif
--- MGrid.cpp ---
//--------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MGrid.h"
#pragma package(smart_init)
//--------------------------------------------------------------
static inline void ValidCtrCheck(TMGrid *)
{
new TMGrid(NULL);
}
//--------------------------------------------------------------
__fastcall TMGrid::TMGrid(TComponent* Owner)
: TStringGrid(Owner)
{
}
//--------------------------------------------------------------
void __fastcall TMGrid::MoveRow( int FromIndex, int ToIndex )
{
inherited::MoveRow( FromIndex, ToIndex );
}
//--------------------------------------------------------------
void __fastcall TMGrid::InsertRow( int Index )
{
// this statement will not work
// ++RowCount;
RowCount = RowCount + 1;
inherited::MoveRow( RowCount - 1, Index );
}
//--------------------------------------------------------------
void __fastcall TMGrid::DeleteRow( int Index )
{
inherited::DeleteRow( Index );
}
//--------------------------------------------------------------
namespace Mgrid
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMGrid)};
RegisterComponents("IDEAtum", classes, 0);
}
}
//--------------------------------------------------------------
Gambit
 

Re:Syntax errors - simple component

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote
[...] For example:
Thanks for the help. I did manage to get most of it but I was
stuck with the typedef for inherited. Using TCustomGrid kept
causing a compiler error but it's handled and on my palette.
Now that that's over, I feel like I should have known how :-d
~ JD