//--------------------------------------------------------------------------- #include #pragma hdrstop #include "ChartThread.h" #pragma package(smart_init) //--------------------------------------------------------------------------- // Important: Methods and properties of objects in VCL can only be // used in a method called using Synchronize, for example: // // Synchronize(UpdateCaption); // // where UpdateCaption could look like: // // void __fastcall ChartThread::UpdateCaption() // { // Form1->Caption = "Updated in a thread"; // } //--------------------------------------------------------------------------- __fastcall ChartThread::ChartThread(void) : TThread(false) { Priority = tpTimeCritical; } void __fastcall ChartThread::DataChart() { Go2Data data = GO2_NULL; DataContext context; context.memory = NULL; double oriz = -294.91; while(!Terminated) { if (Go2System_ReceiveData(system, RECEIVE_TIMEOUT, &data) == GO2_OK) { for(j = 0; j < Go2Data_ItemCount(data); ++j) { Go2Data dataItem = Go2Data_ItemAt(data, j); if (Go2Object_Type(dataItem) == GO2_TYPE_PROFILE_DATA) { unsigned int profilePointCount = Go2ProfileData_Width(dataItem); unsigned int profileSizeBytes = profilePointCount * sizeof(short int); //allocate memory if (context.memory == NULL) { context.memory = (short int*)malloc (NUM_PROFILES * profileSizeBytes); } context.profileWidth = Go2ProfileData_Width(dataItem); context.xResolution = Go2ProfileData_XResolution(dataItem); context.zResolution = Go2ProfileData_ZResolution(dataItem); context.xOffset = Go2ProfileData_XOffset(dataItem); context.zOffset = Go2ProfileData_ZOffset(dataItem); Form1->pointCH->Series[0]->Clear(); for( xz = 0; xz < context.profileWidth; ++xz) { double x = context.xOffset + xz * context.xResolution; double z = context.zOffset + context.memory[ context.profileWidth + xz] * context.zResolution; if ( z <= oriz) { z = 0; } if ( z != 0) {Form1->pointCH->Series[0]->AddXY(xz, z, FloatToStr(x), clRed);} } Form1->pointCH->Refresh(); } } } } } //--------------------------------------------------------------------------- void __fastcall ChartThread::Execute() { while(!Terminated) { //Sleep(2); Synchronize(DataChart); } //---- Place thread code here ---- } //---------------------------------------------------------------------------