請問各位.. 我宣告了一個vector在主要程式,,,如何在thread中也能使用? 下列是我試的程式,只要進入,程式會當住,,不知如何處理,請指導一下!
//主程式片斷
for(int i=0;i
//thread 程式
extern vector DBBuffer;
//---------------------------------------------------------------------------
void __fastcall TransDB::Execute()
{
//---- Place thread code here ----
while(!Terminated)
{
Synchronize(DBprocess);
Sleep(5000);
}
}
//---------------------------------------------------------------------------
void __fastcall TransDB::DBprocess()
{
//write DB if(DBBuffer.empty()) return;
AnsiString DAY;
vector::iterator Ptr = DBBuffer.begin(); DAY = AnsiString(Ptr->Date 4,2) "/" AnsiString(Ptr->Date 2,2) "/" AnsiString(Ptr->Date,2) " ";
DAY = AnsiString(Ptr->Time,2) ":" AnsiString(Ptr->Time 2,2) ":" AnsiString(Ptr->Time 4,2); Form1->TableGPS->Append();
Form1->TableGPS->FieldByName("Unit_id")->AsString = AnsiString((char*)Ptr->ID,Max_ID/2);
Form1->TableGPS->FieldByName("DateTime")->AsDateTime = IncHour(StrToDateTime(DAY),8);
Form1->TableGPS->FieldByName("WGS_LON")->AsFloat = StrToFloat(AnsiString(Ptr->WGS_LON,sizeof(Ptr->WGS_LON)))/100;
Form1->TableGPS->FieldByName("WGS_LAT")->AsFloat = StrToFloat(AnsiString(Ptr->WGS_LAT,sizeof(Ptr->WGS_LAT)))/100;
Form1->TableGPS->FieldByName("Heading")->AsInteger = StrToCurr(AnsiString(Ptr->Heading,sizeof(Ptr->Heading)));
Form1->TableGPS->FieldByName("Speed")->AsFloat = StrToFloat(AnsiString(Ptr->Speed,sizeof(Ptr->Speed)))*1.853;
Form1->TableGPS->FieldByName("Sat#")->AsInteger = (StrToIntDef(AnsiString(Ptr->Sat,sizeof(Ptr->Sat)),0) >= 9)?9:StrToIntDef(AnsiString(Ptr->Sat,sizeof(Ptr->Sat)),0);
Form1->TableGPS->FieldByName("IO1")->AsString = (AnsiString)Ptr->IO1;
Form1->TableGPS->FieldByName("IO2")->AsString = (AnsiString)Ptr->IO2;
Form1->TableGPS->FieldByName("IO3")->AsString = (AnsiString)Ptr->IO3;
Form1->TableGPS->FieldByName("Data_type")->AsString = (AnsiString)Ptr->Type;
Sleep(5000); DBBuffer.erase(Ptr);
}
//---------------------------------------------------------------------------