Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to organize program code into different units

Status
Not open for further replies.

Bachatero

Programmer
Aug 30, 2006
36
NL
Hi all,

My program contains a mainform with 5 tabpages and 3 other forms. I would like to split up my code that belongs to the mainform into different units, for every tabpage a seperate unit. However, I noticed that if you create a new form it creates a new unit as well.

So, the general question is, how can I slit up my code into different units that belongs to the same form.

Advice is very welcome.

Thanks in advance.

Johan
 
Hi Johan,

You can simply write down the classes for each tab page. This class can be written in the units page. Moreover, this is a good approach for programming and it looks like an 0bject Oritented Prograaming.
I think u know how to write the classes and declare the objects in the C++ Builder.
If not reply me...I can help you.

Bye
vinay
 
Hi Vinay,

Thanks for your reply and your suggestion. I am relative new in C++ programming but I tried to write down the code for a tab page in a unit as you suggested. I did got a lot of errors but most of the errors I solved now. However, I have still 3 errors left to solve. All 3 are off the same type:

[C++ Error] Uniformity.cpp(167): E2451 Undefined symbol 'OpenDialog'

However, I defined the variables as follows:

Code:
class TUniformity : public TForm
{
__published:
        TOpenDialog *OpenDialog;
        TButton *bDicomTags;


   private:        // private user declarations
   public:         // public user declarations
         virtual __fastcall TUniformity(TComponent* Owner);
         int GetMyFileSize(FILE *fp);


};

Any idea why ???

Thanks in advance!

Johan
 
Ok,

I moved:

TOpenDialog *OpenDialog;
TButton *bDicomTags;

from the Uniformity.h to the Uniformity.cpp and now my E2451 error is gone. However, if I call Uniformity->LeesUniformityMap(); now I got the following error:

[C++ Error] Main.cpp(344): E2316 'LeesUniformityMap' is not a member of 'TTabSheet'

How can I solve this ?

Johan

 
Ok,

I solved it. No compiler errors anymore however, if I load a file my program crasshes. Before I moved the code to a seperate unit it didn't crash.

The following message is displayed:

---------------------------
Debugger Exception Notification
---------------------------
Project NemaReview.exe raised exception class EAccessViolation with message 'Access violation
at address 0040B76A in module 'NemaReview.exe'. Read of address 000002F0'. Process stopped.
Use Step or Run to continue.
---------------------------
OK Help
---------------------------

---------------------------
NEMA Review
---------------------------
Access violation at address 0040B76A in module 'NemaReview.exe'. Read of address 000002F0.
---------------------------
OK
---------------------------

The program stops at:

OpenDialog->Filter = "Uniformity|*.ima"; see colored text

Code:
bool TUniformity::LeesUniformityMap()
{
  int    FileSize;
  long   *buffer;
  int    length,a;
  char   aFileName[20];
  int    ImageSize,ImagePosition,nImages = 1;
  double filesize;
  long   tagsize;
  
  ACR_TAG acrtag, *tag = NULL;
  FILE          *fp;

  [COLOR=red]OpenDialog->Filter = "Uniformity|*.ima";[/color]     

        if (OpenDialog->Execute())
          {
             FileName = ExtractFileName(OpenDialog->FileName); // FileName = 5FOV.IMA
             FileDir = ExtractFileDir(OpenDialog->FileName);
             strcpy(aFileName,FileName.c_str()); // Converteer AnsiString naar chars
          }                                      

       // Open the file:
      if ((fp = fopen(aFileName, "r")) == NULL)
      {
        MessageBox(NULL,"Er is geen file geselecteerd. Er is geannuleerd.",NULL,0);
        return 0;
      }
      //if (fp==NULL) exit (1); 

      a = IsDitEenDicomFile(fp);
      
      if ( a == FRMT_DICM)
      {
      ShowMessage("Dit is een Dicom file");
      }
      else ShowMessage("Dit is geen Dicom file");

      // get length of file:
      FileSize = GetMyFileSize(fp);

     // allocate memory:
     buffer = (long*) malloc (FileSize);
     //if (buffer == NULL) exit (2);

     // read data as a block:
     fread (buffer,1,FileSize,fp);

     fclose(fp);

    free (buffer);

    //UpDateStatusLine(StatusLineRight,FileName + "  file geladen !!!");

    bDicomTags->Enabled = TRUE;

  return 0; 

}

If have no idea how to debug these type of problems.

Suggestions are very welcome!

Thanks in advance.

Johan
 
Hi all,


Since I did spit up my code into different units I got the following error:

[Linker Error] Unresolved external '_GainValues' referenced from I:\C++_PROJECTS_JOHAN\NEMA_REVIEW\MAIN.OBJ

Any help is very appreciated!

Thanks in advance,

Johan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top