start a class in BCB

Hi,

   How do I start a class in BCB ? new a "Unit" ? or something else ? many thanks !
LVL 1
meow00Asked:
Who is Participating?
 
George TokasCommented:
Addition at andrewjb post:
The answer is anywere as andrewjb posted...
If you want that piece of code (the class ) to be reusable then it will be better to have its own space...
So...
File|New|Unit....
This will create a unitx.cpp and unitx.h...
Rename it to something to remember that it is your class... I.e. "MyClass.cpp" & "MyClass.h"...
At the header file declare the class:
#ifndef MyClassH
#define MyClassH
class MyClass
{
private:
//your private members
protected:
//the protected members here
public:
  MyClass();//constructor
  ~MyClass();//destructor. Those MUST be public

};
#endif

Those for the header. As for .cpp
#include MyClass.h

MyClass::MyClass()
{
//Constructor code here if needed.
}

MyClass::~MyClass()
{
//Destructor code here if needed.
}

Thats all for the class to reuse it anywere you like at any project...
As for expanding the class its pretty straightforward...
Declare a function at .h and write the code at .cpp...
The same way you are working at main form on any project at BCB...
Remember that and by default when you are working on BCB and starting a new application you are working in a class the Form1 class...

gtokas.
0
 
andrewjbCommented:
Errr... put it where you want? A new unit is probably kind of neat and tidy. Rather depends what you want to do... You could create classes in your main form's unit if you want, it'd just get rather monolothic and messy. BCB is pretty much the same as any other compiler in this respect. What's the problem?
0
 
balderCommented:
There is no class wizard in BCB, you just declare and define your classes directly in new or existing files as explained above.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.