Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Defineing classes

1 view
Skip to first unread message

us...@domain.invalid

unread,
Feb 29, 2008, 10:23:17 AM2/29/08
to
Hi, I'm building a slideshow program in Turbo C++ 2006, the general idea
is that the program should allow the user to view images in a random
order from the chosen directory. The random functionality must be in its
own class. I'm using TSearchRec to search the directory and TStringList
to store the file paths for retrieval. Here is what I have so far:

*****SlideShow.cpp:

#include <vcl.h>
#pragma hdrstop
#include "SlideShow.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfmMain *fmMain;
//---------------------------------------------------------------------------
__fastcall TfmMain::TfmMain(TComponent* Owner)
: TForm(Owner)
{
DoubleBuffered = true;
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::btnOpenImageClick(TObject *Sender)
{
if (!OpenPictureDialog1 -> Execute()) return;
Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::Timer1Timer(TObject *Sender)
{
RandomSequence.SetSeed(i);
Image1->Picture->LoadFromFile(FileNameList->Strings[RandomSequence.GetVal()]);
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::Open1Click(TObject *Sender)
{
btnOpenImageClick(this);
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::Close1Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::btnStartSlideshowClick(TObject *Sender)
{
Timer1->Enabled = !Timer1->Enabled;// Toggles slideshow on/off
// Toggles button lable according to state.
if(Timer1->Enabled == false)
{
btnStartSlideshow->Caption = "Start Slideshow";
}
else
btnStartSlideshow->Caption = "Stop Slideshow";
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::RandomShow1Click(TObject *Sender)
{
btnStartSlideshowClick(this);
}
//---------------------------------------------------------------------------

*****SlideShow.h:

#ifndef SlideShowH
#define SlideShowH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <ExtDlgs.hpp>
#include <jpeg.hpp>

#include "C_Random.h" // Adding Random class to SlideShow.cpp
#include <Menus.hpp>
//---------------------------------------------------------------------------
class TfmMain : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TImage *Image1;
TOpenPictureDialog *OpenPictureDialog1;
TSpeedButton *btnOpenImage;
TTimer *Timer1;
TMainMenu *MainMenu1;
TMenuItem *File1;
TMenuItem *Open1;
TMenuItem *Save1;
TMenuItem *SaveAs1;
TMenuItem *Close1;
TMenuItem *Edit1;
TSpeedButton *btnStartSlideshow;
TMenuItem *View1;
TMenuItem *SlideShow1;
TMenuItem *RandomShow1;
void __fastcall btnOpenImageClick(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall Open1Click(TObject *Sender);
void __fastcall Close1Click(TObject *Sender);
void __fastcall btnStartSlideshowClick(TObject *Sender);
void __fastcall RandomShow1Click(TObject *Sender);
private: // User declarations
C_Random RandomSequence;
TStringList* FileNameList; // Construct list
public: // User declarations
__fastcall TfmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
int i; // Counter available in cpp file
//---------------------------------------------------------------------------
extern PACKAGE TfmMain *fmMain;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

*****C_Random.cpp:

#pragma hdrstop
#pragma package(smart_init)
//---------------------------------------------------------------------------
#include "C_Random.h"
#include "stdlib.h"
#include "time.h"

int C_Random::GetVal()
{
return mIntRandom;
}
//---------------------------------------------------------------------------
void C_Random::SetRange(int IntRange)
{
mIntRange = IntRange;
}
//---------------------------------------------------------------------------
void C_Random::SetSeed(unsigned IntSeed=0) //(int IntSeed)
{
srand((unsigned)time(NULL));// Seeds random using system clock
// Sets mIntRand to a seeded random number
mIntRandom = random(mIntRange);
// in the range of 1 to mIntRange
}
//---------------------------------------------------------------------------
void C_Random::FillStringList(TStringList *FileNameList)
{
int i =0; // Set counter to zero

// Collect all files of same type
TSearchRec SearchRec;
AnsiString Dir = ExtractFileDir(OpenPictureDialog1->FileName); // Get
dir on its own
AnsiString Ext = ExtractFileExt(OpenPictureDialog1->FileName); // Get
ext on its own
int iAttributes = faAnyFile; // Read only hidden etc


// Provide FindFirst with dir and filename example
if (FindFirst(Dir+"\\*"+Ext, iAttributes, SearchRec) == 0)
{
FileNameList->Add(Dir+"\\"+SearchRec.Name);
i++;

while (FindNext(SearchRec) == 0)
{
FileNameList->Add(Dir+"\\"+SearchRec.Name);
i++;
}
RandomSequence.SetRange(FileNameList->Count); // Ramdom range set to
list count
}
else
ShowMessage("Directory search failed");

FindClose(SearchRec);
}

*****C_Random.h

#ifndef C_RandomH
#define C_RandomH

#include <stdlib.h>
//---------------------------------------------------------------------------
class C_Random
{
public:
int GetVal();
void SetRange(int IntRange);
void SetSeed(unsigned IntSeed);
void FillStringList(TStringList *FileNameList);

private:
int mIntRandom;
int mIntRange;
};
//---------------------------------------------------------------------------
#endif

*****Code ends****

Any help here would be greatly appreciated as the deadline for this fast
approaches!!!

Will

unread,
Feb 29, 2008, 11:00:11 AM2/29/08
to
Oops! I should also have mentioned that I get the following compiler errors:
[C++ Error] C_Random.h(13): E2293 ) expected
[C++ Error] C_Random.cpp(39): E2147 'TStringList' cannot start a
parameter declaration
[C++ Error] C_Random.cpp(40): E2316 'C_Random::FillStringList(int *)' is
not a member of 'C_Random'

Many thanks for any help!

Bob Gonder

unread,
Feb 29, 2008, 11:31:27 AM2/29/08
to
Will wrote:

>[C++ Error] C_Random.h(13): E2293 ) expected
>[C++ Error] C_Random.cpp(39): E2147 'TStringList' cannot start a
>parameter declaration
>[C++ Error] C_Random.cpp(40): E2316 'C_Random::FillStringList(int *)' is
>not a member of 'C_Random'

C_Random.cpp does not include the header for TStringList.
So it doesn't know what that is.

Also, you are using TC2006 while this group is
about the old Turbo C/C++ (pre Builder) versions.
TC2006 is covered in groups with cppbuilder in their names.

Will

unread,
Feb 29, 2008, 12:23:19 PM2/29/08
to no...@notmindspring.invalid
Bob Gonder wrote:
>
> C_Random.cpp does not include the header for TStringList.
> So it doesn't know what that is.
>
> Also, you are using TC2006 while this group is
> about the old Turbo C/C++ (pre Builder) versions.
> TC2006 is covered in groups with cppbuilder in their names.
>

Many thanks for the help Bob, I'l be sure to use one of the builder
groups in future! Thanks again.

0 new messages