Rene
2008-04-27 18:58:23 UTC
Hello to all,
I am using BCB6 for a course I am taking in C++. Along with many console
applications, I have to write simple windows programs every now and again
(without having any real knowledge about windows programming in general and
not having learned about objects and stuff like that so please don't make
the answer to my question too difficult ;-) ).
Today I stumbled across a problem. I have a button on my form and am
writing the function that is executed when someone presses that button. So
far no problems. However, in that function I would like to call another
function that is outside this button function because I want to use it as
well when the user presses another button. The extra function is supposed to
update a ListBox which is named "ListBox1overzicht" (that box exists, that
is not the problem).
I have made an extra .h file in which a struct is defined and the function I
am talking about has a prototype in there as well. I will past the source of
the cpp file here:
<source code>
//---------------------------------------------------------------------------
#include <vcl.h>
#include "eigendefinitiesPC8.h"
#pragma hdrstop
#include "PC8C.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int huidigFormaat=0;
Spreker* lijstPointer=NULL;
Spreker* nieuweLijstPointer=NULL;
//XXXXXXXXXXXXXXXXXXXXXXXXX
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1toevoegenClick(TObject *Sender)
{
nieuweLijstPointer = new Spreker[huidigFormaat+1];
for (int teller=0; teller<huidigFormaat; teller++)
{
nieuweLijstPointer[teller]=lijstPointer[teller];
}
nieuweLijstPointer[huidigFormaat].naam=this->Edit1naam->Text;
nieuweLijstPointer[huidigFormaat].telefoonnummer=this->Edit2telefoonnummer->Text;
nieuweLijstPointer[huidigFormaat].onderwerp=this->Edit3onderwerp->Text;
nieuweLijstPointer[huidigFormaat].honorarium=this->Edit4honorarium->Text.ToDouble();
huidigFormaat+=1;
delete [] lijstPointer;
lijstPointer=nieuweLijstPointer;
delete [] nieuweLijstPointer;
nieuweLijstPointer=NULL;
}
//---------------------------------------------------------------------------
void updateOverzicht(Spreker* const lijst, const int grootte)
{
this->ListBox1overzicht->Clear();
// A lot of different things will be added here later...
}
</source code>
The problem is that when I place the function declaration (function I am
talking about is called updateOverzicht) somewhere outside the
Button1toevoegenClick function (first I wanted to place it just below the
declaration of my global variables, where I put the XXXXXX's), I get the
comment that "ListBox1overzicht" is an undefined symbol. I can put any other
objects from my application in the function, they are all undefined. When I
put the function inside the Button1toevoegenClick function everything is OK.
So my question is: Where should I put those "general" functions so that they
are available from every place in the program AND the symbols are defined
instead of undefined?
Thank You very much in advance!
Yours sincerely,
Rene
I am using BCB6 for a course I am taking in C++. Along with many console
applications, I have to write simple windows programs every now and again
(without having any real knowledge about windows programming in general and
not having learned about objects and stuff like that so please don't make
the answer to my question too difficult ;-) ).
Today I stumbled across a problem. I have a button on my form and am
writing the function that is executed when someone presses that button. So
far no problems. However, in that function I would like to call another
function that is outside this button function because I want to use it as
well when the user presses another button. The extra function is supposed to
update a ListBox which is named "ListBox1overzicht" (that box exists, that
is not the problem).
I have made an extra .h file in which a struct is defined and the function I
am talking about has a prototype in there as well. I will past the source of
the cpp file here:
<source code>
//---------------------------------------------------------------------------
#include <vcl.h>
#include "eigendefinitiesPC8.h"
#pragma hdrstop
#include "PC8C.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int huidigFormaat=0;
Spreker* lijstPointer=NULL;
Spreker* nieuweLijstPointer=NULL;
//XXXXXXXXXXXXXXXXXXXXXXXXX
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1toevoegenClick(TObject *Sender)
{
nieuweLijstPointer = new Spreker[huidigFormaat+1];
for (int teller=0; teller<huidigFormaat; teller++)
{
nieuweLijstPointer[teller]=lijstPointer[teller];
}
nieuweLijstPointer[huidigFormaat].naam=this->Edit1naam->Text;
nieuweLijstPointer[huidigFormaat].telefoonnummer=this->Edit2telefoonnummer->Text;
nieuweLijstPointer[huidigFormaat].onderwerp=this->Edit3onderwerp->Text;
nieuweLijstPointer[huidigFormaat].honorarium=this->Edit4honorarium->Text.ToDouble();
huidigFormaat+=1;
delete [] lijstPointer;
lijstPointer=nieuweLijstPointer;
delete [] nieuweLijstPointer;
nieuweLijstPointer=NULL;
}
//---------------------------------------------------------------------------
void updateOverzicht(Spreker* const lijst, const int grootte)
{
this->ListBox1overzicht->Clear();
// A lot of different things will be added here later...
}
</source code>
The problem is that when I place the function declaration (function I am
talking about is called updateOverzicht) somewhere outside the
Button1toevoegenClick function (first I wanted to place it just below the
declaration of my global variables, where I put the XXXXXX's), I get the
comment that "ListBox1overzicht" is an undefined symbol. I can put any other
objects from my application in the function, they are all undefined. When I
put the function inside the Button1toevoegenClick function everything is OK.
So my question is: Where should I put those "general" functions so that they
are available from every place in the program AND the symbols are defined
instead of undefined?
Thank You very much in advance!
Yours sincerely,
Rene