Pokusao sam da stavim dva CGauge-a na formu koja ce da prate izvrsavanje dva inserta u bazu, evo koda, ali nesto ne stima,
uvek se odradi jedan pa drugi. Ima li neko ovakvih iskustava a spreman je da ih podeli sa drugima?
Unit1.cpp
TForm1 *Form1;
TMyThread *proc;
TMyThread *proc1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMyThread *proc = new TMyThread(false);
proc->Priority = tpNormal ;
proc->Suspend();
TMyThread1 *proc1 = new TMyThread1(false);
proc1->Priority = tpNormal;
proc1->Suspend();
proc->Resume();
proc1->Resume();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete proc;
delete proc1;
}
//---------------------------------------------------------------------------
Thread.cpp
//---------------------------------------------------------------------------
__fastcall TMyThread::TMyThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{
Synchronize(doo);
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::doo()
{
static int n;
int max = StrToInt(Form1->LEdit1->Text);
Form1->CGauge1->MaxValue = max;
for ( n=0; n<=max; n++ ){
Form1->SQL->SQL->Text = "insert into id (id,a,b,c) values ("
+ IntToStr(n) + ","
+ IntToStr(n*10) + ","
+ IntToStr(n*50) + ","
+ IntToStr(n*150) + ")";
Form1->SQL->ExecSQL(true);
Form1->CGauge1->Progress = n;
}
Application->ProcessMessages();
//ShowMessage("Uspesno insertovano " + IntToStr(max) + " redova.");
}
//---------------------------------------------------------------------------
Thread1.cpp
//---------------------------------------------------------------------------
__fastcall TMyThread1::TMyThread1(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TMyThread1::Execute()
{
Synchronize(dooo);
}
//---------------------------------------------------------------------------
void __fastcall TMyThread1::dooo()
{
static int n;
int max1 = StrToInt(Form1->LEdit1->Text) + StrToInt(Form1->LEdit1->Text);
Form1->CGauge2->MaxValue = max1;
for ( n=0; n<=max1; n++ ){
Form1->SQL->SQL->Text = "insert into id1 (a,b,c) values ("
+ IntToStr(n) + ","
+ IntToStr(n*10) + ","
+ IntToStr(n*150) + ")";
Form1->SQL->ExecSQL(true);
Form1->CGauge2->Progress = n;
}
Application->ProcessMessages();
//ShowMessage("Uspesno insertovano " + IntToStr(max) + " redova.");
}
//---------------------------------------------------------------------------