[错误 E2356 Type mismatch in redeclaration of 'TForm1'怎么修改?
我从书上抄的代码,应该是没有问题的但是我编译不出来,总是出现
[C++ Error] Unit1.cpp(13): E2356 Type mismatch in redeclaration of 'TForm1'
[C++ Error] Unit1.cpp(13): E2141 Declaration syntax error
这两个问题,我不知道是哪错了,那位高手给解答一下,小女子在这里先谢过了!
原代码
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
const int MaxPoints =15;
struct TRPoint{
float X,Y;
};
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTimer *Timer1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormPaint(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
TRPoint Points[MaxPoints];
float Rotation;
int PointCount;
void __fastcall RotatePoints();
public: // User declarations
virtual __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *TForm1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "math.h"
#include <stdlib.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *TForm1;
//--------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Canvas->Pen->Color = clTeal;
Rotation = 0;
PointCount = MaxPoints;
RotatePoints();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
int centerX=ClientWidth/2;
int centerY=ClientHeight/2;
int radius=min(centerY,centerX);
Canvas->Ellipse(0,0,radius*2,radius*2);
int i,j;
for(i=1;i<PointCount;i++){
for(j=i+1;j<PointCount;j++){
Canvas->MoveTo(radius+floor(Points[i].X*radius),radius+floor(Points[i].Y*radius));
Canvas->LineTo(radius+floor(Points[i].X*radius),radius+floor(Points[i].Y*radius));
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
RotatePoints();
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RotatePoints()
{
const float M_2PI = 2*M_PI;
float StepAngle = M_2PI/PointCount;
Rotation+=M_PI/32;
if(Rotation>StepAngle)
Rotation-= StepAngle;
int i;
float j;
for(i=0,j=Rotation;i<PointCount;i++,j+=StepAngle)
{
Points[i].X = cos(j);
Points[i].Y = sin(j);
}
}