Hi,

I'm relatively new to C++ Builder and the language itself, and my code is now becoming quite long. I was looking to take advantage of using a seperate class for certain methods, however I've come across a problem.

Here's an example of my code in the new class;

TShape* shape;
shape = new TShape(this);
[B]shape->Parent = frm1->Panel1;[/B]

Having included an

#include "Unit2.h"

line of code within my main form's header and compiling, an error message was displayed stating that there was an:

Undefined Symbol 'frm1'

I cannot understand where I have gone wrong and was hoping someone had an idea, would be a great help!

You have to find out where frm1 is declared. Is it a member of a class in which the code snippet you posted resides? Look in the *.h files and see where that variable is declared. Or is it even in a header file.

You have to find out where frm1 is declared. Is it a member of a class in which the code snippet you posted resides? Look in the *.h files and see where that variable is declared. Or is it even in a header file.

Thanks for replying, explanation is not my strongest point!

My project group has 2 Units, the main one that was created along with the project, known as Unit1.cpp along with Unit1.h and Unit1.dfm.

The form frm1 is the class declared in Unit1.h as a public TForm. as shown below:

#include "Unit2.h"
//---------------------------------------------------------------------------
class Tfrm1 : public TForm
{

The code snippet I posted originally belongs to Unit2.cpp which I created myself.

Tfrm1 *frm1;

Is also included in the cpp file.

#include "Unit2.h"

the above code I added now resides within Unit1.h.

I had assumed that adding an include for Unit2's header file in Unit1's header file would link the two c++ files together.

Does that make sense to you? I was struggling to get my head around it to begin with. It's not a big problem but If I'm asked about C++ within my job role in the future, it's something to know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.