Solved

multiple .cpp files in an OWL project

Posted on 1997-09-08
2
319 Views
Last Modified: 2012-06-27
I am using Borland C++ 4.5

What I would like to know is how I should prepare code such that multiple .cpp files can be utilised within a project. Specifically, how should I break up an existing single .cpp file into two parts i.e., so that it becomes two .cpp files, and yet can be compiled within the project environment as one.

As an example, I enclose a program that operates a simple dialog box from a  popup menu. Possibly someone could explain how I might break this into two .cpp files for compilation within the project environment.

your assistance is most appreciated

regards

Richard

 

#include <cstring.h>
#include <windows.h>
#include <owl\edit.h>
#include <owl\window.h>
#include <owl\window.rh>
#include <owl\scroller.h>
#include <fstream.h>
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\dialog.h>
#pragma hdrstop
#include "dialog2.rh"

const UINT MaxEdit = 48;

 ===========================================================
// Sample dialog
// ===========================================================

class MyDialog: public TDialog
{
public:
  MyDialog(TWindow* parent, TResId resId);
  ~MyDialog();

private:
      TEdit *EditControl1;
      TEdit *EditControl2;
      TEdit *EditControl3;
   virtual void SetupWindow();
 
protected:
  void CmCancel();
  void CmOk();
DECLARE_RESPONSE_TABLE(MyDialog);
};

DEFINE_RESPONSE_TABLE1(MyDialog, TDialog)
  EV_COMMAND(CM_CANCEL, CmCancel),
  EV_COMMAND(CM_OK, CmOk),
END_RESPONSE_TABLE;

void MyDialog::SetupWindow()
{
      TDialog::SetupWindow();
      Scroller = new TScroller(this, 5, 5, 300, 300);
      string text;
      ifstream file("Datafile.txt",ios::binary);

      text.read_file(file);
      EditControl1->Insert(text.c_str());
      text.read_file(file);
      EditControl2->Insert(text.c_str());
      text.read_file(file);
      EditControl3->Insert(text.c_str());
}


void MyDialog::CmCancel()
{
 SendMessage(WM_CLOSE);
}

void MyDialog::CmOk()
{
      char buffer[MaxEdit];
      int len = EditControl1->GetText(buffer,MaxEdit);
      ofstream file("Datafile.txt",ios::binary);
      file.write(buffer,len);
      file<<'\0'; // insert null to delimit text
      len = EditControl2->GetText(buffer,MaxEdit);
      file.write(buffer,len);
      file<<'\0'; // insert null to delimit text
      len = EditControl3->GetText(buffer,MaxEdit);
      file.write(buffer,len);
      file<<'\0'; // insert null to delimit text
      file.close();
      SendMessage(WM_CLOSE);
}


// ===========================================================
// The application's main window
// ===========================================================

class TDiagWin: public TFrameWindow {
public:
  TDiagWin(TWindow* parent, const char far* title);
protected:
  void CmTest();
DECLARE_RESPONSE_TABLE(TDiagWin);
};

DEFINE_RESPONSE_TABLE1(TDiagWin, TFrameWindow)
  EV_COMMAND(CM_TEST, CmTest),
END_RESPONSE_TABLE;

// Constructor
TDiagWin::TDiagWin(TWindow* parent, const char far* title)
  : TFrameWindow(parent, title),
    TWindow(parent, title)
{
  AssignMenu(ID_MENU);
}

// Construct and execute a modal dialog box
void
TDiagWin::CmTest()
{
(new MyDialog(this, ID_DIALOG)->Execute());
}

MyDialog::~MyDialog()
{
}

MyDialog::MyDialog(TWindow* parent, TResId resId)
      : TWindow(parent),TDialog(parent, resId)
{

   EditControl1 = new TEdit(this,IDE_FIND1);
      EditControl2 = new TEdit(this,IDE_FIND2);
      EditControl3 = new TEdit(this,IDE_FIND3);
}

// ===========================================================
// The application class
// ===========================================================

class TDiagApp: public TApplication {
public:
  TDiagApp(const char far* name)
    : TApplication(name) {}
  void InitMainWindow();
};

// Initialize the program's main window
void
TDiagApp::InitMainWindow()
{
  EnableBWCC();  // Loads custom control DLL
  MainWindow = new TDiagWin(0, "Sample Dialog Box");
}

#pragma argsused

// Main program
int
OwlMain(int argc, char* argv[])
{
  TDiagApp app("DiagApp");
  return app.Run();
}
0
Comment
Question by:aa941438
2 Comments
 
LVL 3

Accepted Solution

by:
gaohong earned 200 total points
ID: 1169204
good programming style could save you troubles and leads to easy
maintaining.

In general, for each class, say "MyClass"
you should have a header file called myclass.h, in which
you put class declaration and necessary header files and other
variables, if globals or static or control ID used.

It is nothing wrong to stuck all into one file, only cause you
difficulties.

You put your class definition in myclass.cpp file.

For your codes above.

It should have mydialog.h mydialog.cpp for class MyDialog
myframe.h myframe.cpp for class TDiagWin
myapp.h myapp.cpp for class TDiagApp

Put .h files in include directory, .cpp files in aother directory.

After you generate a new project, .ide file
right click to add .cpp files, while specify the include path
in project options.

good luck
gaohong xie

                 
0
 

Author Comment

by:aa941438
ID: 1169205
many thanks

Richard
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Socket Programming (Unix) 8 142
Dialogbox API leak? 18 99
Eclipse IDE - Cannot copy/paste from console output 8 260
FMX TEdit KeyUp handler detecting  "enter" key 4 14
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question