新手学习。请问如何设计一个等待呀!!!
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
bool flag1;
bool flag2;
bool flag3;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Form1->Edit1->Text="";
Form1->Edit2->Text="";
Form1->Edit3->Text="";
Form1->Edit4->Text="";
Form1->Edit4->Enabled =false;
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float avg;
if(flag1==true&&flag2==true&&flag3==true){
avg=(StrToFloat(Form1->Edit1->Text)+
StrToFloat(Form1->Edit2->Text)+
StrToFloat(Form1->Edit3->Text))/3.0;
Form1->Edit4->Text=FloatToStr(avg);
if(avg<60.0)
ShowMessage("你的平均成绩比较低");
flag1=false;
flag2=false;
flag3=false;
}
}
//---------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if(Form1->Edit1->Text==""){
ShowMessage("高等数学成绩为空");
Form1->Edit1->SetFocus();
return;
}
if(StrToFloat(Form1->Edit1->Text)<0)
{
ShowMessage("高等数学成绩为空");
Form1->Edit1->SetFocus();
return;
}
flag1=true;
}
//---------------------------------------
void __fastcall TForm1::Edit2Change(TObject *Sender)
{
if(Form1->Edit2->Text==""){
ShowMessage("模拟电路成绩为空");
Form1->Edit2->SetFocus();
return;
}
if(StrToFloat(Form1->Edit2->Text)<0)
{
ShowMessage("模拟电路成绩为空");
Form1->Edit2->SetFocus();
return;
}
flag2=true;
}
//---------------------------------------
void __fastcall TForm1::Edit3Change(TObject *Sender)
{
if(Form1->Edit3->Text==""){
ShowMessage("数字电路成绩为空");
Form1->Edit3->SetFocus();
return;
}
if(StrToFloat(Form1->Edit3->Text)<0)
{
ShowMessage("数字电路成绩为空");
Form1->Edit3->SetFocus();
return;
}
flag3=true;
}
上面红字部分,如何设计一个等待(除了加上数字外),才能让它不程序一执行就提示“高等代数”!!!
请高手教下!!!才学的很多多不太了解!!!
[解决办法]
加一个全局变量
bool inited = false;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Form1->Edit1->Text="";
Form1->Edit2->Text="";
Form1->Edit3->Text="";
Form1->Edit4->Text="";
inited = true; // 加上这行
Form1->Edit4->Enabled =false;
}
每个 EditChange中
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if(!inited)return; // 加上这行
if(Form1->Edit1->Text==""){
ShowMessage("高等数学成绩为空");
...
话说我觉得没必要在 Edit1Change 中检验数据,
统一放到点击按钮时比较好