unit2.cpp

来自「RS232 program multithread for borland C+」· C++ 代码 · 共 44 行

CPP
44
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
#include "Unit1.h"
#pragma package(smart_init)
extern HANDLE hComm;
//---------------------------------------------------------------------------

//   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 Unit2::UpdateCaption()
//      {
//        Form1->Caption = "Updated in a thread";
//      }
//---------------------------------------------------------------------------

__fastcall TReadThread::TReadThread(bool CreateSuspended)
        : TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TReadThread::Execute()
{
        //---- Place thread code here ----
    while (! Terminated) Synchronize(ReadData);    
}
//---------------------------------------------------------------------------

void __fastcall TReadThread::ReadData()
{
  String Temp;
  char inbuff[1024];
  DWORD nBytesRead, dwEvent, dwError;
  COMSTAT cs;
   if (hComm == INVALID_HANDLE_VALUE) return;
    //

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?