There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
My first tutorial in C++


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
eddie5659's Avatar
Computer Specs
Moderator with 18,344 posts.
 
Join Date: Mar 2001
Location: Bradford, England
24-Jan-2005, 03:29 PM #1
Smile My first tutorial in C++
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:

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:

Code:
//---------------------------------------------------------------------------

#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:

Code:
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "About.h"
//--------------------------------------------------------------------- 
#pragma resource "*.dfm"
TAboutBox1 *AboutBox1;
//--------------------------------------------------------------------- 
__fastcall TAboutBox1::TAboutBox1(TComponent* AOwner)
	: TForm(AOwner)
{
}
//---------------------------------------------------------------------
eddie
__________________
Just go with the flow, like a twig on the shoulders of a mighty stream
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
25-Jan-2005, 04:04 PM #2
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.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run
eddie5659's Avatar
Computer Specs
Moderator with 18,344 posts.
 
Join Date: Mar 2001
Location: Bradford, England
25-Jan-2005, 04:34 PM #3
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
__________________
Just go with the flow, like a twig on the shoulders of a mighty stream
eddie5659's Avatar
Computer Specs
Moderator with 18,344 posts.
 
Join Date: Mar 2001
Location: Bradford, England
03-Feb-2005, 05:46 PM #4
Posted to this newsgroup, so will let you know which book they suggest...hopefully

borland.public.cppbuilder.non-technical

eddie
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:11 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.