//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CGAUGES"
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActTestExecute(TObject *Sender)
{
ShowMessage("test");
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionStartExecute(TObject *Sender)
{
ListBox->Clear();
ListBox->Items->Append("2");
m_CurrentValue=3;
this->Timer->Enabled=true;
}
//---------------------------------------------------------------------------
bool TFormMain::Pass(int value)
{
int MaxCircle=floor(sqrt(value));
bool result=true;
int index=0;
int i=2;
while (i<=MaxCircle)
{
//进度
CGauge->MaxValue=MaxCircle;
CGauge->Progress=i;
Application->ProcessMessages();
//判断
if (value%i==0)
{
result=false;
//break;
}
//修正
index++;
i=StrToInt(this->ListBox->Items->Strings[index]);
};
return(result);
}
void __fastcall TFormMain::TimerTimer(TObject *Sender)
{
if(Timer->Tag==0)
{
Timer->Tag=1;
if (Pass(m_CurrentValue))
{
this->ListBox->Items->Append(IntToStr(m_CurrentValue));
};
this->Caption=IntToStr(m_CurrentValue);
m_CurrentValue+=2;
Timer->Tag=0;
};
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionStartUpdate(TObject *Sender)
{
this->ActionStart->Enabled=!(this->Timer->Enabled);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionStopUpdate(TObject *Sender)
{
this->ActionStop->Enabled=this->Timer->Enabled;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionStopExecute(TObject *Sender)
{
this->Timer->Enabled=false;
this->ActionContinue->Tag=1;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionContinueExecute(TObject *Sender)
{
this->Timer->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionContinueUpdate(TObject *Sender)
{
this->ActionContinue->Enabled=(!(this->Timer->Enabled))&&(ActionContinue->Tag>0);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
this->DoubleBuffered=true;
}
//---------------------------------------------------------------------------