# My first tutorial in C++



## eddie5659 (Mar 19, 2001)

Hiya

I'm happy, just completed it. Its a Notepad that actually works, with an About box, etc 

This is the code, if you want to have a go. Of course, many will be able to do this, but I was dead happy when I completed it. The debugger came up a few times, but that was a blessing, as I learnt a few things on the way 

This is the main code:


```
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ActnList.hpp>
#include <ComCtrls.hpp>
#include <ImgList.hpp>
#include <StdActns.hpp>
#include <Menus.hpp>
#include <ToolWin.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TRichEdit *RichEdit1;
        TStatusBar *StatusBar1;
        TImageList *ImageList1;
        TActionList *ActionList1;
        TAction *FileNew;
        TAction *FileSave;
        TAction *HelpIndex;
        TAction *HelpAbout;
        TEditCut *EditCut1;
        TEditCopy *EditCopy1;
        TEditPaste *EditPaste1;
        TFileOpen *FileOpen1;
        TFileSaveAs *FileSaveAs1;
        TFileExit *FileExit1;
        THelpContents *HelpContents1;
        TMainMenu *MainMenu1;
        TMenuItem *File1;
        TMenuItem *New1;
        TMenuItem *Open1;
        TMenuItem *Save1;
        TMenuItem *SaveAs1;
        TMenuItem *N1;
        TMenuItem *Exit1;
        TMenuItem *Edit1;
        TMenuItem *Cut1;
        TMenuItem *Copy1;
        TMenuItem *Paste1;
        TMenuItem *Help1;
        TMenuItem *Contents1;
        TMenuItem *Index1;
        TMenuItem *N2;
        TMenuItem *About1;
        TToolBar *ToolBar1;
        TToolButton *ToolButton1;
        TToolButton *ToolButton2;
        TToolButton *ToolButton3;
        TToolButton *ToolButton4;
        TToolButton *ToolButton5;
        TToolButton *ToolButton6;
        TToolButton *ToolButton7;
        TToolButton *ToolButton8;
        void __fastcall FileNewExecute(TObject *Sender);
        void __fastcall FileOpen1Accept(TObject *Sender);
        void __fastcall FileSaveAs1BeforeExecute(TObject *Sender);
        void __fastcall FileSaveExecute(TObject *Sender);
        void __fastcall FileSaveAs1Accept(TObject *Sender);
        void __fastcall HelpContents1Execute(TObject *Sender);
        void __fastcall HelpIndexExecute(TObject *Sender);
        void __fastcall HelpAboutExecute(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
private:	// User declarations
public:		// User declarations
AnsiString FileName;

        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
```
Which was made up as follows:


```
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "About.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FileNewExecute(TObject *Sender)
{
RichEdit1->Clear();
FileName = "untitled.txt";
StatusBar1->Panels->Items[0]->Text = FileName;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FileOpen1Accept(TObject *Sender)
{
RichEdit1->Lines->LoadFromFile (FileOpen1->Dialog->FileName);
FileName = FileOpen1->Dialog->FileName;
StatusBar1->Panels->Items[0]->Text = FileName;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileSaveAs1BeforeExecute(TObject *Sender)
{
FileSaveAs1->Dialog->InitialDir = ExtractFilePath (FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileSaveExecute(TObject *Sender)
{
if (FileName == "untitled.txt")
    FileSaveAs1->Execute();
else
    RichEdit1->Lines->SaveToFile(FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileSaveAs1Accept(TObject *Sender)
{
FileName = FileSaveAs1->Dialog->FileName;
RichEdit1->Lines->SaveToFile(FileName);
StatusBar1->Panels->Items[0]->Text = FileName;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::HelpContents1Execute(TObject *Sender)
{
const static int HELP_TAB = 15;
const static int CONTENTS_ACTIVE = -3;
Application->HelpCommand(HELP_TAB, CONTENTS_ACTIVE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::HelpIndexExecute(TObject *Sender)
{
const static int HELP_TAB = 15;
const static int INDEX_ACTIVE = -2;
Application->HelpCommand(HELP_TAB, INDEX_ACTIVE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::HelpAboutExecute(TObject *Sender)
{
AboutBox1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->HelpFile = ExtractFilePath(Application->ExeName) + "TextEditor.hlp";
FileName = "untitled.txt";
StatusBar1->Panels->Items[0]->Text = FileName;
RichEdit1->Clear();
}
//---------------------------------------------------------------------------
```
And I had to create the about box, etc like so:


```
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "About.h"
//--------------------------------------------------------------------- 
#pragma resource "*.dfm"
TAboutBox1 *AboutBox1;
//--------------------------------------------------------------------- 
__fastcall TAboutBox1::TAboutBox1(TComponent* AOwner)
	: TForm(AOwner)
{
}
//---------------------------------------------------------------------
```
eddie


----------



## Shadow2531 (Apr 30, 2001)

I'd give your code a try, but cannot since I use MinGW. You are using the visual components library that comes with borland.

I'm not sure if the library works with any other compilers and if you can just download the library or you have to purchase it.

It's staight windows.api or cross-platform, cross-compiler libraries like wxwidgets for me.


----------



## eddie5659 (Mar 19, 2001)

Ah, okay. I see what you mean. I was very happy when I completed it, but there is one very big drawback........I did the turtorial, and the book has been finished. Don't know what everything does, or what I can do with it 

Seems if you get the Personel version, they don't supply any deep books. Not good, as I don't want to get the Enterprise version (~£200) or Professional (~£2000) without doing a bit of swotting.

I have found some books in Amazon, but as you don't use Borland, I may ask in their newsgroups. But, I'll post them anyway, just in case.

C++ Builder 6: Developer's Guide (Wordware Delphi Developer's Library) 

Jarrod Hollingworth, Satya Sai Kolachina (Editor) 

£43.50 

This comprehensive guide provides in-depth discussion on topics such as Windows development, database development, Internet development including web services, VCL/CLX component development, and more. Every chapter includes extensive sample programs tested on C++ Builder 6. The enterprise edition of C++ Builder 6 is also included on the CD. Includes CD


C++ with Borland C++Builder: An Introduction to the ANSI/ISO Standard and Object Oriented Windows Programming 
Richard Kaiser 

£29.40


C++ with the Borland C++Builder presents comprehensively and systematically all language elements of the ANSI/ISO standard of C++. Contexts and language concepts are in the foreground. The author uses the version 6 of the Borland C++Builder as development system. This visual system is the C++ variant of the Pascal development system Delphi and makes a simple development of programs for Windows possible. Almost all examples and exercises are Windows programs. However, since the ANSI/ISO standard of C++ is in the foreground, this book is also suitable for readers who work with other compilers. The class library of the C++Builder (VCL) is used as an example of a class hierarchy. The CD-ROM contains many examples and exercises with solutions. 

But, I was looking at this one:

C++ Primer Plus 
Stephen Prata 

£25.55 

Update to a computer industry classic; over 100,000 copies sold in previous editions. 
Contains over 20 new programming exercises and newly improved examples. 
Suitable as a tutorial or as the core text for C++ programming courses. 
Teaches fundamentals of programming including principles of structured code and top-down design. 
Includes a handy tear-out "Quick Reference Card". 


eddie


----------



## eddie5659 (Mar 19, 2001)

Posted to this newsgroup, so will let you know which book they suggest...hopefully 

borland.public.cppbuilder.non-technical

eddie


----------

