help with progress bar and timer


2004-09-19 12:33:09 PM
cppbuilder78
Hi,
My code doesn't seem to update the progress bar and I don't think I'm
doing this correctly anyway. What's the best way to update the
progress bar on a non-modal form, that contains a TTimer control, in a
non-modal application that uses a library call (custom library) that
does all the processing? It seems that the timer and progress bar
controls are not updating. However the global variable that I use in
the timer is actually updating correctly.
The basic design is
TMainForm <>--->TActionForm <>--->MKUtils
has has
Now, here is the problem. How can I update the progress bar on
TActionForm when the code doing all the work is in
MKUtils::DoStuff(...)?
The relevant code in the form TActionForm is (see example code for
MKUtils::DoStuff below)
//...
// guiProgressBarCounter is defined as global in the WinMain as
//
// unsigned int guiProgressBarCounter = 0;
//
// which is not included here
// include files...
// ...
const unsigned long gkulMax = 1331200;
extern unsigned int guiProgressBarCounter;
//...
//*******************************************************
// Create button
//*******************************************************
void __fastcall TActionForm::Create(TObject *Sender)
{
string sLabel = txtLabel->Text.c_str();
ProgressBar1->Max = gkulMax; //100;
Timer1->Enabled = true;
MKUtils objMKUtils;
objMKUtils.DoStuff(sLabel,
false);
String sTemp(guiProgressBarCounter);
String sTemp2 = "guiProgressBarCounter " + sTemp;
MessageBox(dlgFormatDiskImage->Handle,
sTemp2.c_str(),
"Message Box",
MB_OK);
guiProgressBarCounter = 0;
ProgressBar1->Position = 0;
}
//*******************************************************
// Timer
//*******************************************************
void __fastcall TActionForm::Timer1Timer(TObject *Sender)
{
ProgressBar1->StepBy(25);
Application->ProcessMessages();
ProgressBar1->StepIt();
if(ProgressBar1->Position == gkulMax)
{
Timer1->Enabled = false;
ProgressBar1->Position = 0;
}
else
{
ProgressBar1->Position = ProgressBar1->Position +
guiProgressBarCounter;
}
}
The relevant code for MKUtils::DoStuff follows...
MKUtils::DoStuff(sLabel,
false)
{
//...
extern unsigned int guiProgressBarCounter;
bool bCompletedFatBlocks = false;
for (unsigned long i = kiMaxBlocksToWrite; i < gkulMax; ++i)
{
//...
// Update the counter so it can be accessed externally,
// say in form TActionForm
++guiProgressBarCounter;
//...
}
//...
}
I'm using Borland C++ Builder 3 on W98. I'm new to using this, so
please bear this in mind.
Regards,
Michael