[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1904
  • Last Modified:

C++Builder 6.0 and the error [Linker Error] Unresolved external 'TForm1::'

As I was typing down my code I tried to compile and I got the error:
[Linker Error] Unresolved external 'TForm1::' referenced from E:\blah blah \file.obj

What is the mistake? Where is the mistake?

My form's header file is:
//---------------------------------------------------------------------------

#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Menus.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:      // IDE-managed Components
        TMainMenu *mainMenu;
        TMenuItem *subFile;
        TMenuItem *subRead;
        TMenuItem *subExit;
        TMenuItem *subGraph;
        TMenuItem *subDraw;
        TMenuItem *subClear;
        TLabel *lblPoints;
        TImage *imgGraph;
        TLabel *lblMsg;
        TMenuItem *subDestroy;
        TMenuItem *subTopY;
        TMenuItem *subFindY;
        TMenuItem *subFindSlope;
        TMenuItem *N1;
        TMenuItem *N2;
        TMenuItem *subSteep;
        TMenuItem *subAdd;
        void __fastcall subExitClick(TObject *Sender);
        void __fastcall subReadClick(TObject *Sender);
        void __fastcall subDrawClick(TObject *Sender);
        void __fastcall subClearClick(TObject *Sender);
        void __fastcall subDestroyClick(TObject *Sender);
        void __fastcall subTopYClick(TObject *Sender);
        void __fastcall subFindYClick(TObject *Sender);
        void __fastcall subFindSlopeClick(TObject *Sender);
        void __fastcall subSteepClick(TObject *Sender);
        void __fastcall subAddClick(TObject *Sender);

private:      // User declarations
public: __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

By the way I am a newbie so please try to keep it simple:

0
Trooper80
Asked:
Trooper80
1 Solution
 
waysideCommented:
> extern PACKAGE TForm1 *Form1;

"extern" allows the compiler to use a variable named Form1 in this source file, and tells the linker to look somewhere else for the actual declaration of Form1.

So, somewhere in one (and only one) of your source files you must actually declare the variable:

PACKAGE TForm1 *Form1;

Now the linker can find it and link it.

Hope this helps.
0
 
Orion188Commented:
Hi
I think you can't find enough help just with copying the Header.
Didn't you do any coding for the form?
Let's see the code. I think there should be the error.

Also tell me about the way you created this form and application.
Waiting to hear from you
0
 
Trooper80Author Commented:
This is the list.cpp file:
struct point{
float x;
float y;
};

struct LI{
point val;
LI* next;
LI* previous;
};

struct LL{
LI* head;
LI* last;
int size;
};


*********************************************************
This is the TimoMot file:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("main.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->CreateForm(__classid(TForm1), &Form1);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------


********************************************************************************


And this is the main.cpp
//--------------------------------------------------------------------------
#include <vcl.h>
#include <fstream.h>

#pragma hdrstop

#include "main.h"
#include "list.cpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
LL mylist;

//---------------------------------------------------------------------------
int readNumbers(float *numbers){
ifstream fin("test.txt");
int end=0;
int j=0;
int k=0;
char numList[100];
char num[10];
char ch;

while(fin.get(ch)){
      if(ch=='\n'){
      numList[end]=',';
      end++;
      continue;
      }
      if(isdigit(ch)||ch=='.'||ch=='-'||ch==','){
      numList[end]=ch;
      end++;
      continue;
      }
}

for(int i=0;i<=end;i++){
      if(isdigit(numList[i])||numList[i]=='.'||numList[i]=='-'){
            num[j]=numList[i];
            (j)++;
      }
      else{
            num[j]='\0';
            numbers[k]=atof(num);
            j=0;
            k++;
                if(k>40)break;
        }
}
return k;
}

void initLL(LL* list){
list->head=0;
list->last=0;
list->size=0;
}

void typePoints(){
Form1->lblPoints->Caption=" ";
LI* t=mylist.head;

    for(int i=1;i<=mylist.size;i++){
    Form1->lblPoints->Caption=Form1->lblPoints->Caption+"\n("+t->val.x+","+t->val.y+")";
    t=t->next;
    }
}

//---------------------------------------------------------------------------
void append(point* mypoint){
        LI* tmp=new LI;
        tmp->val.x=mypoint->x;
        tmp->val.y=mypoint->y;
        tmp->next=0;
        tmp->previous=0;

        if(!mylist.head){
                mylist.head=tmp;
                mylist.last=tmp;
                mylist.size++;
        }
        else{
                mylist.last->next=tmp;
                tmp->previous=mylist.last;
                mylist.last=tmp;
                mylist.size++;
        }

}
//---------------------------------------------------------------------------
void appendSorted(float x,float y){
        LI* tmp=mylist.head;
        LI* added=new LI;

        added->val.x=x;
        added->val.y=y;

        if(mylist.size==0){
        Form1->lblMsg->Caption="Message: Point added as first";
          point* p=new point;
          p->x=x;p->y=y;
          append(p);
        }
        else{
             if(x<tmp->val.x){
             added->next=tmp;
             mylist.head=added;
             }
             else{
                  while(tmp->next&&x>tmp->next->val.x)tmp=tmp->next;
                  added->next=tmp->next;
                  tmp->next=added;
                  mylist.size++;
                  if(tmp==mylist.last)
                  mylist.last=added;
                  Form1->lblMsg->Caption="Message: The point added is:"+FloatToStr(x);
             }
        }
typePoints();
}
//---------------------------------------------------------------------------
void drawAxis(){
        Form1->imgGraph->Canvas->Pen->Color = TColor(clNavy);
        Form1->imgGraph->Canvas->MoveTo(0,100);
        Form1->imgGraph->Canvas->LineTo(450,100);
        Form1->imgGraph->Canvas->MoveTo(50,200);
        Form1->imgGraph->Canvas->LineTo(50,0);
        Form1->imgGraph->Canvas->TextOut(460,90,"X-Axis");
        Form1->imgGraph->Canvas->TextOut(15,0,"Y-Axis");
        Form1->imgGraph->Canvas->Pen->Color = TColor(clBlack);
        int j=0;
        for(int i=0;i<200;i+=20){
        Form1->imgGraph->Canvas->TextOut(50+i*2,200,IntToStr(i));
        Form1->imgGraph->Canvas->TextOut(0,88-j*2,IntToStr(j));
        j+=10;
        }
}
//---------------------------------------------------------------------------
void drawGraph(){
        LI* tmp=mylist.head;
        if(!tmp){
        Form1->lblMsg->Caption="Message:The list is empty";
        return;
        }
        Form1->imgGraph->Canvas->MoveTo(50+tmp->val.x*2,100-tmp->val.y*2);
        while(tmp){
        Form1->imgGraph->Canvas->LineTo(50+tmp->val.x*2,100-tmp->val.y*2);
        tmp=tmp->next;
        }
}
//---------------------------------------------------------------------------
void clearGraph(){
        Form1->imgGraph->Canvas->Pen->Color=clWindow;
        Form1->imgGraph->Canvas->Rectangle(0, 0,500,300);
        drawAxis();
        Form1->subDraw->Enabled=1;
        Form1->subClear->Enabled=0;
}
//---------------------------------------------------------------------------
void drawPoint(float x,float y,TColor color){
Form1->imgGraph->Canvas->Pen->Color = TColor(color);
Form1->imgGraph->Canvas->Pie(48+x*2,98-y*2, 52+x*2,102-y*2, 50+x*2,100-y*2, 50+x*2,100-y*2);
Form1->imgGraph->Canvas->Pen->Color = TColor(clBlack);
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::subExitClick(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::subReadClick(TObject *Sender)
{
point mypoint;
float numbers[40];
int k=readNumbers(numbers);
subRead->Enabled=0;
subDraw->Enabled=1;
subClear->Enabled=1;
subDestroy->Enabled=1;
subFindSlope->Enabled=1;
subFindY->Enabled=1;
subTopY->Enabled=1;
subSteep->Enabled=1;
subAdd->Enabled=1;
subFindYofX->Enabled=1;
subFirst->Enabled=1;
subLast->Enabled=1;


lblPoints->Caption="The points:";

initLL(&mylist);

        for(int i=0;i<k-1;i+=2){
        mypoint.x=numbers[i];
        mypoint.y=numbers[i+1];
        append(&mypoint);
        lblPoints->Caption=lblPoints->Caption+"\n("+mypoint.x+","+mypoint.y+")";
        drawAxis();
        }
}

//---------------------------------------------------------------------------
void __fastcall TForm1::subDrawClick(TObject *Sender)
{
drawGraph();
        subRead->Enabled=0;
        subDraw->Enabled=0;
        subClear->Enabled=1;
        lblMsg->Caption="Message:Drawed Graph";        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subClearClick(TObject *Sender)
{
        clearGraph();
        lblMsg->Caption="Message:Cleared Graph";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subDestroyClick(TObject *Sender)
{
LI* tmp=mylist.head;

        if(!tmp){
        lblMsg->Caption="The list is empty";
        }
        else{
                for(int i=1;i<=mylist.size;i++){
                mylist.head=tmp->next;
                delete tmp;
                tmp=mylist.head;
                }
        }
        mylist.head=0;mylist.last=0;
        subRead->Enabled=1;
        subDraw->Enabled=0;
        subClear->Enabled=0;
        subDestroy->Enabled=0;
        subFindSlope->Enabled=0;
        subFindY->Enabled=0;
        subTopY->Enabled=0;
        subSteep->Enabled=0;
        subAdd->Enabled=0;
        subFindYofX->Enabled=0;
        subFirst->Enabled=0;
        subLast->Enabled=0;


        lblPoints->Caption="Points Destroyed";
        clearGraph();
        subDraw->Enabled=0;
        lblMsg->Caption="Message:Cleared and Destroyed Graph";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subTopYClick(TObject *Sender)
{
 int x=0;
 LI* tmp=mylist.head;
        if(!tmp){
                lblMsg->Caption="Message: The list is empty";
        }
        else{
             int max=tmp->val.y;
             for(int i=1;i<=mylist.size;i++){
                if(max<tmp->val.y){
                max=tmp->val.y;
                x=tmp->val.x;
                }
                tmp=tmp->next;
             }
        drawPoint(x,max,clYellow);
        lblMsg->Caption="Message: The top y value is "+IntToStr(max);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subFindYClick(TObject *Sender)
{
LI* tmp=mylist.head;
        if(!tmp){
                lblMsg->Caption="Message: The list is empty";
        }
        else{
            lblMsg->Caption="Message:The values below 0 are:";
            for(int i=1;i<mylist.size;i++){
                if(tmp->val.y<0){
                drawPoint(tmp->val.x,tmp->val.y,clLime);
                lblMsg->Caption=lblMsg->Caption+"   "+FloatToStr(tmp->val.y);
                }
                tmp=tmp->next;
            }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subFindSlopeClick(TObject *Sender)
{

        float x=StrToFloat(InputBox("Enter the x value:","The value must not be"
                                    " more than 400","0"));
        float slope1=0; float slope2=0;
        LI* tmp=mylist.head;

        if(x>mylist.last->val.x){
        lblMsg->Caption="Message:The value is invalid";
        return;
        }

        if(!tmp){
        lblMsg->Caption="Message:The list is empty";
        }
        else{
             if(!tmp->next){
             lblMsg->Caption="Message:The list has only one element";
             }
             else{
                for(int i=1;i<mylist.size;i++){
                     if(x>=tmp->val.x&&x<=tmp->next->val.x){
                     slope1=(tmp->next->val.y-tmp->val.y)/(tmp->next->val.x-tmp->val.x);
                     lblMsg->Caption="Message:The slope of the line at given x is:"+FloatToStr(slope1);
                     return;
                     }
                tmp=tmp->next;
                }
             }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subSteepClick(TObject *Sender)
{
float x=0,y=0;float slope=0,test=0;
        LI* tmp=mylist.head;
        if(!tmp){
                lblMsg->Caption="Message: The list is empty";
        }
        else{
            if(!tmp->next){
                lblMsg->Caption="Message: The list has one element";
            }
            else{
                x=tmp->val.x;
                for(int i=1;i<mylist.size;i++){
                   if(tmp->val.x==tmp->next->val.x){
                   lblMsg->Caption="Message: The x value is :"+FloatToStr(tmp->val.x)+" "
                                   "and the steppest slope is: Not Defined";
                   return;
                   }
                        else{
                            test=(tmp->next->val.y-tmp->val.y)/(tmp->next->val.x-tmp->val.x);
                            if(abs(slope)<abs(test)){
                            slope=test;
                            x=tmp->val.x;y=tmp->val.y;
                            }
                        }
                     tmp=tmp->next;
                   }
                }
            lblMsg->Caption="Message: The x value is :"+FloatToStr(x)+" "
                            "and the steppest slope is:"+slope+" "+FloatToStr(y);
            }//Else
drawPoint(x,y,clRed);        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subAddClick(TObject *Sender)
{
float x= StrToFloat(InputBox("Enter the x value:","The value must not be"
                             " more than 400","0"));
float y= StrToFloat(InputBox("Enter the y value:","The value must not be"
                             " more than 400","0"));
appendSorted(x,y);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subFindYofXClick(TObject *Sender)
{
        LI* tmp=mylist.head;
        float m,b;
        float x=StrToFloat(InputBox("Enter the x value:","The value must not be"
                                    " more than 400","0"));
        float y=0;

        if(!mylist.size){
        lblMsg->Caption="Message: The list is empty";
        return;
        }
        else{
             if(mylist.size==1){
             lblMsg->Caption="Message: Cannot determine point";
             return;
             }
             else{
                 for(int i=1;i<mylist.size;i++){
                      if(x>=tmp->val.x&&x<=tmp->next->val.x){
                      m=(tmp->next->val.y-tmp->val.y)/(tmp->next->val.x-tmp->val.x);
                        if(tmp->val.x==0&&tmp->val.y==0){
                        b=tmp->next->val.y-(m*tmp->next->val.x);
                        }
                        else{
                        b=tmp->val.y-(m*tmp->val.x);
                        }
                      y=b+m*x;
                      lblMsg->Caption="Message: The value of y at x="+FloatToStr(x)+" "
                      "is "+FloatToStr(y);
                      drawPoint(x,y,clMoneyGreen);
                      return;
                      }
                tmp=tmp->next;
                }

             }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subFirstClick(TObject *Sender)
{
        LI* tmp=mylist.head;
        float b=0,m=0,x=0;

        float y=StrToFloat(InputBox("Enter the y value:","The value must not be"
                                    " more than 400","0"));
        if(mylist.size==0){
                lblMsg->Caption="Message: The list is empty";
        }
        else{
             if(mylist.size==1){
                if(y==tmp->val.y){
                lblMsg->Caption="Message: The value of y at x="+FloatToStr(tmp->val.x)+" "
                                        "is "+FloatToStr(y);
                drawPoint(tmp->val.x,y,clMaroon);
                return;
                }
                else{
                lblMsg->Caption="Message: The list has only one point"
                                       " and it is not equal to given y";
                return;
                }
             }
             else{
             for(int i=1;i<mylist.size;i++){
                if(y>=tmp->val.y&&y<=tmp->next->val.y){
                m=(tmp->next->val.y-tmp->val.y)/(tmp->next->val.x-tmp->val.x);
                        if(tmp->val.x==0&&tmp->val.y==0){
                        b=tmp->next->val.y-(m*tmp->next->val.x);
                        }
                        else{
                         b=tmp->val.y-(m*tmp->val.x);
                        }
                x=(y-b)/m;
                lblMsg->Caption="Message: The value of y at x="+FloatToStr(x)+" "
                                       "is "+FloatToStr(y);
                drawPoint(x,y,clMaroon);
                return;
                }
                tmp=tmp->next;
             }
             }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::subLastClick(TObject *Sender)
{
LI* tmp=mylist.last;
        float b=0,m=0,x=0,x1=0,x2=0,y1=0,y2=0;

        float y=StrToFloat(InputBox("Enter the y value:","The value must not be"
                                    " more than 400","0"));
        if(mylist.size==0){
                lblMsg->Caption="Message: The list is empty";
        }
        else{
             if(mylist.size==1){
                if(y==tmp->val.y){
                lblMsg->Caption="Message: The value of y at x="+FloatToStr(tmp->val.x)+" "
                                        "is "+FloatToStr(y);
                drawPoint(tmp->val.x,y,clMaroon);
                return;
                }
                else{
                Form1->lblMsg->Caption="Message: The list has only one point"
                                       " and it is not equal to given y";
                return;
                }
             }
             else{
             for(int i=1;i<mylist.size;i++){
                if(y>=tmp->previous->val.y&&y<=tmp->val.y){
                   m=(tmp->val.y - tmp->previous->val.y)/(tmp->val.x - tmp->previous->val.x);
                   if(tmp->val.x!=0&&tmp->val.y!=0){
                        b=tmp->val.y-(m*tmp->val.x);
                        }
                        else{
                        b=tmp->previous->val.y-(m*tmp->val.x);
                        }
                   x=(y-b)/m;
                   lblMsg->Caption="Message: The value of y at x="+FloatToStr(x)+" "
                                   "is "+FloatToStr(y);
                   drawPoint(x,y,clCream);
                   return;
                }
             tmp=tmp->previous;
             }//for
             }//else
         }//else

}
//---------------------------------------------------------------------------

The funny thing is that I found a backup of my program and I appended some code I had in the non-working project and it works. I just need to know what can cause such an error in order to know what to do next time.
By the way my project is standalone in order to work on any computer I run it without installing any extra libraries.


0
 
CayceCommented:
Most probably it was the .bpr (project) file that was misconfigured or corrupted. The easiest way to fix this is by recreating an empty application project, then adding all the units back.
0
 
George TokasCommented:
Hello there...
You use BCB6 (first things first...).
>>[Linker Error] Unresolved external 'TForm1::' referenced from E:\blah blah \file.obj
This is NOT the full message from the message window....
Anyway..:-)
You are missing the following:
        TMenuItem *subFindYofX;
        void __fastcall subFindYofXClick(TObject *Sender);
        void __fastcall subFirstClick(TObject *Sender);
        void __fastcall subLastClick(TObject *Sender);

Add them at the main.h file and it will work..(At least 4 me it worked)

Regards
gtokas.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now