Session 1

Overview of the Turbo C++ IDE, building from the command line, simple Windows application

Session #1

The main topic of this session was to present the IDE environment and show how a minimal windows application is built.

A "bare-bones" Windows application:
Manual1.cppForm1.cpp
#include <vcl.h>
USEFORM("Form1.cpp", theForm);
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  Application->Initialize();
  Application->CreateForm(__classid(TForm), &theForm);
  Application->Run();
  return 0;
}
#include <vcl.h>
TForm *theForm;

Compile:

bcc32 -c Manual1.cpp
bcc32 -c Form1.cpp
Link (all on one line):
ilink32 -x -L"C:\program files\borland\bds\4.0\lib\debug;C:\program files\borland\bds\4.0\lib;C:\program files\borland\bds\4.0\lib\obj" 
c0w32.obj Manual1.obj Form1.obj,Manual1.exe,,rtl.lib vcl.lib import32.lib cp32mt.lib,, 
The application at runtime: (Exciting, eh?)
There are batch files to build everything and to just link the program. You can download all of the files in this zip.


A slightly more complicated application. It demonstrates deriving a form from the base class TForm and creating components (objects) at runtime in the constructor.

Manual2.cppMyForm2.cpp
#include <vcl.h>
USEFORM("MyForm2.cpp", MyForm2);
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  Application->Initialize();
  Application->CreateForm(__classid(TMyForm2), &MyForm2);
  Application->Run();
  return 0;
}
#include <vcl.h>
#include "MyForm2.h"
#pragma resource "*.dfm"

TMyForm2 *MyForm2;

__fastcall TMyForm2::TMyForm2(TComponent* Owner) : TForm(Owner)
{
  AddText = new TButton(this);
  AddText->Parent = this;
  AddText->Left = 20;
  AddText->Top = 20;
  AddText->Caption = "Add text";

  Edit = new TEdit(this);
  Edit->Parent = this;
  Edit->Left = AddText->Left + AddText->Width + 5;
  Edit->Top = AddText->Top;
  Edit->Width = 150;

  ListBox = new TListBox(this);
  ListBox->Parent = this;
  ListBox->Left = AddText->Left;
  ListBox->Top = AddText->Top + AddText->Height + 5;
  ListBox->Width = AddText->Width + Edit->Width + 5;
  ListBox->Height = 100;

  AddText->OnClick = ClickButton;
}

void __fastcall TMyForm2::ClickButton(TObject *)
{
  ListBox->Items->Add(Edit->Text);
}
MyForm2.dfm (Resource file)
object MyForm2: TMyForm2
end
MyForm2.h
class TMyForm2 : public TForm
{
  private:
    TButton *AddText;
    TEdit *Edit;
    TListBox *ListBox;
  public:
    __fastcall TMyForm2(TComponent* Owner);
    void __fastcall ClickButton(TObject *);
};

The application at runtime:

You can download all of the files in this zip.


Another slightly more complicated application. It demonstrates creating components in the resource file (and handled in the __published section of the class).

Manual3.cppMyForm3.cpp
#include <vcl.h>
USEFORM("MyForm3.cpp", MyForm3);
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  Application->Initialize();
  Application->CreateForm(__classid(TMyForm3), &MyForm3);
  Application->Run();
  return 0;
}
#include <vcl.h>
#include "MyForm.h"
#pragma resource "*.dfm"

TMyForm3 *MyForm3;

__fastcall TMyForm3::TMyForm3(TComponent* Owner) : TForm(Owner)
{
  AddText = new TButton(this);
  AddText->Parent = this;
  AddText->Left = 20;
  AddText->Top = 20;
  AddText->Caption = "Add text";

  Edit = new TEdit(this);
  Edit->Parent = this;
  Edit->Left = AddText->Left + AddText->Width + 5;
  Edit->Top = AddText->Top;
  Edit->Width = 150;

  ListBox = new TListBox(this);
  ListBox->Parent = this;
  ListBox->Left = AddText->Left;
  ListBox->Top = AddText->Top + AddText->Height + 5;
  ListBox->Width = AddText->Width + Edit->Width + 5;
  ListBox->Height = 100;

  AddText->OnClick = ClickButton;
}

void __fastcall TMyForm3::ClickButton(TObject *)
{
  ListBox->Items->Add(Edit->Text);
}
MyForm3.dfm (Resource file)
object MyForm: TMyForm
  object Button: TButton
    Caption = 'Hello'
    Left = 200
    Top = 180
  end
  object Scroll: TScrollBar
    Kind = sbVertical
    Align = alRight
    Width = 16
  end
end
MyForm3.h
class TMyForm3 : public TForm
{
  __published:
    TButton *Button;
    TScrollBar *Scroll;
  private:
    TButton *AddText;
    TEdit *Edit;
    TListBox *ListBox;
  public:
    __fastcall TMyForm3(TComponent* Owner);
    void __fastcall ClickButton(TObject *);
};

The application at runtime:

You can download all of the files in this zip.

Exercises

  1. Try these examples on your own. This will tell you if you have installed Turbo C++ correctly on your computer.
  2. I spent about 20 minutes during the presentation talking about all of the things that are wrong (from a usability perspective) with this very simple application that copies the text from the edit box (TEdit) into the list box (TListBox) when the user clicks the button (TButton). I then discussed various ways that these usability problems could be solved and implemented some of them.
    Re-create this application and solve some of the problems any way you see fit. (Note: This is a little challenging since I haven't really talked about how to work in Turbo C++ yet. However, some of you might be up for the challenge.) Reminder: Some of the issues are: