M
Michael Bell
Using Borland Builder 5 I am trying to get a very simple first working
use of a class to work. Following the example of the OU course MT262
as nearly as I can, I have Created files named Class First,
ClassSecond, and ClassThird. And it's still wrong!
It is a windows application, but I don't think that's relevant.
ClassFirst.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
USERES("ClassFirst.res");
USEFORM("ClassFirstU.cpp", Form1);
USEFORM("ClassSecond.cpp", Frame1); /* TFrame: File Type */
USEUNIT("ClassThird.cpp");
USEUNIT("ClassSecond.cpp");
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
//-------------------------------------
ClassFirstU.h
//---------------------------------------------------------------------------
#ifndef ClassFirstUH
#define ClassFirstUH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ClassSecond.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Box;
TEdit *Operator;
TEdit *Show1;
TEdit *Input1Box;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TEdit *Show2;
TEdit *ShowProduct;
TLabel *Label4;
TLabel *Label5;
TLabel *Label6;
TLabel *Label7;
TButton *ShowButton;
TButton *EnterInput1Button;
TButton *EnterInput2Button1;
TButton *MultiplyButton;
void __fastcall EnterInput1ButtonClick(TObject *Sender);
private: // User declarations
int Input1;
int Input2;
int Product;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
ClassFirstU.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClassFirstU.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EnterInput1ButtonClick(TObject *Sender)
{
Input1 = Input1Box ->Text.ToInt();
Show1->Text = Input1;
}
//---------------------------------------------------------------------------
ClassSecond.h
#define ClassSecondH
#include "ClassThird.h"
//---------------------------------------------------------------------------
class NumberBoardClass
{
protected:
NumberBoardType Board();
NumberBoardType ShowOne();
NumberBoardType Multiply(void);
public:
NumberBoardType Show();
};
#endif
ClassSecond.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClassSecond.h"
//---------------------------------------------------------------------------
NumberBoardType NumberBoardClass::Multiply(void)
{
int LocalNumber;
LocalNumber = NumberBoardType.Input1 * NumberBoardClass.Input2;
NumberBoardType.Product = LocalNumber;
return Board;
}
#pragma package(smart_init)
ClassThird.h
//---------------------------------------------------------------------------
#ifndef ClassThirdH
#define ClassThirdH
//---------------------------------------------------------------------------
struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};
#endif
ŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒ..
And the error messages I get are :-
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardType'
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardClass'
[C++ Error] ClassSecond.cpp(13): E2108 Improper use of typedef
'NumberBoardType'
[C++ Error] ClassSecond.cpp(14): E2235 Member function must be called
or its address taken
I really don't know what's wrong!
Michael Bell
--
use of a class to work. Following the example of the OU course MT262
as nearly as I can, I have Created files named Class First,
ClassSecond, and ClassThird. And it's still wrong!
It is a windows application, but I don't think that's relevant.
ClassFirst.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
USERES("ClassFirst.res");
USEFORM("ClassFirstU.cpp", Form1);
USEFORM("ClassSecond.cpp", Frame1); /* TFrame: File Type */
USEUNIT("ClassThird.cpp");
USEUNIT("ClassSecond.cpp");
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
//-------------------------------------
ClassFirstU.h
//---------------------------------------------------------------------------
#ifndef ClassFirstUH
#define ClassFirstUH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ClassSecond.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Box;
TEdit *Operator;
TEdit *Show1;
TEdit *Input1Box;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TEdit *Show2;
TEdit *ShowProduct;
TLabel *Label4;
TLabel *Label5;
TLabel *Label6;
TLabel *Label7;
TButton *ShowButton;
TButton *EnterInput1Button;
TButton *EnterInput2Button1;
TButton *MultiplyButton;
void __fastcall EnterInput1ButtonClick(TObject *Sender);
private: // User declarations
int Input1;
int Input2;
int Product;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
ClassFirstU.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClassFirstU.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EnterInput1ButtonClick(TObject *Sender)
{
Input1 = Input1Box ->Text.ToInt();
Show1->Text = Input1;
}
//---------------------------------------------------------------------------
ClassSecond.h
#define ClassSecondH
#include "ClassThird.h"
//---------------------------------------------------------------------------
class NumberBoardClass
{
protected:
NumberBoardType Board();
NumberBoardType ShowOne();
NumberBoardType Multiply(void);
public:
NumberBoardType Show();
};
#endif
ClassSecond.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClassSecond.h"
//---------------------------------------------------------------------------
NumberBoardType NumberBoardClass::Multiply(void)
{
int LocalNumber;
LocalNumber = NumberBoardType.Input1 * NumberBoardClass.Input2;
NumberBoardType.Product = LocalNumber;
return Board;
}
#pragma package(smart_init)
ClassThird.h
//---------------------------------------------------------------------------
#ifndef ClassThirdH
#define ClassThirdH
//---------------------------------------------------------------------------
struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};
#endif
ŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒ..
And the error messages I get are :-
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardType'
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardClass'
[C++ Error] ClassSecond.cpp(13): E2108 Improper use of typedef
'NumberBoardType'
[C++ Error] ClassSecond.cpp(14): E2235 Member function must be called
or its address taken
I really don't know what's wrong!
Michael Bell
--