954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

BorlandC++ Builder Error with creating classes

Hi,

I created the class for converting decimal to binary numbers and I wish to make the Windows application but there's an error:

E2285 Could not find a match for 'TForm1::TForm1()'

The source code:

//---------------------------------------------------------------------------

#include <vcl.h>
#include<math.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
class Convert: public TForm1{
     static unsigned int i;
     int conv_number[1000];
     unsigned int to_bin(unsigned int);    

      public:
      void convert(unsigned int);  
      void print_bin(); 
      Convert():TForm1(){};
      };

unsigned int Convert::i=0;

void Convert::convert(unsigned int number){

    while(number!=0)
        {
         conv_number[i]=to_bin(number);
         i++;
         number=number/2;
         }

    }
  
unsigned int Convert::to_bin(unsigned int y)
                        {
         double z;
         z=fmod(y,2);
         if (z==1)
         return 1;
         return 0;
}    


void Convert::print_bin(){
     
     while(i!=0)
     {
               
       i--;
       Memo1->Text=conv_number[i];
            }

}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
Memo1->Text='\0' ;
}
//---------------------------------------------------------------------------

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

Convert *obj;
obj = new Convert;
obj->convert(3123);
obj->print_bin();
}
//---------------------------------------------------------------------------


At the first place, I had problem with "Memo1 not defined" error. So I made class inherits TForm1 class and it disappeared. Also I had to create new object using new. And finally I get this error. I can't understand the problem. This is my first attempt to add class from Dev to Borland.
This class works fine in console.

Thanks.

MrEARTHSHAcKER
Junior Poster in Training
68 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

I solved this problem!

I just should remove all connection between my and TForm class and call Memo1 like Form1->Memo1. So code should look like this:

//---------------------------------------------------------------------------

#include <vcl.h>
#include<math.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
class Convert{
     static unsigned int i;
     int conv_number[1000];
     unsigned int to_bin(unsigned int);  
      public:
      void convert(unsigned int); 
      void print_bin(); 

      };

unsigned int Convert::i=0;
prethodni>>
void Convert::convert(unsigned int number){

    while(number!=0)
        {
         conv_number[i]=to_bin(number);
         i++;
         number=number/2;
         }

    }

unsigned int Convert::to_bin(unsigned int y)
                        {
         double z;
         z=fmod(y,2);
         if (z==1)
         return 1;
         return 0;
}    


void Convert::print_bin(){

     while(i!=0)
     {
               
       i--;
         Form1->Memo1->Text = Form1->Memo1->Text + conv_number[i];
            }

}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
Memo1->Text='\0' ;
}
//---------------------------------------------------------------------------

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

Convert *obj;
obj = new Convert;

obj->convert(2);
obj->print_bin();
}
//---------------------------------------------------------------------------


Special thanks to a guy who gave me the idea of solving this problem! :)

MrEARTHSHAcKER
Junior Poster in Training
68 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You