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.cpp | Form1.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 (You can compile both at the same time as well):
Link (all on one line):bcc32 -c Manual1.cpp bcc32 -c Form1.cpp
The application at runtime: (Exciting, eh?)ilink32 -x -L"C:\Program Files (x86)\Borland\BDS\4.0\lib\debug;C:\Program Files (x86)\Borland\BDS\4.0\lib;C:\Program Files (x86)\Borland\BDS\4.0\lib\obj" c0w32.obj Manual1.obj Form1.obj,Manual1.exe,,rtl.lib vcl.lib import32.lib cp32mt.lib,,
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.cpp | MyForm2.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.cpp | MyForm3.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 MyForm3: TMyForm3 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
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 a lot about how to work in the IDE yet. However, some of you might be up for the challenge.) Reminder: Some of the issues are that I mentioned:
![]()
![]()