unit2.cpp

来自「一个串口通信的源码」· C++ 代码 · 共 49 行

CPP
49
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>

#include "Unit2.h"
#include "Unit1.h"
#include "Pcomm.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 Thread1::UpdateCaption()
//      {
//        Form1->Caption = "Updated in a thread";
//      }
//---------------------------------------------------------------------------
__fastcall Thread1::Thread1(bool CreateSuspended)
    : TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall Thread1::Execute()
{
int i=0;
unsigned char ch;
    try
    {
      Form1->fp = fopen(Form1->StaticText1->Caption.c_str(), "rb");
      fseek(Form1->fp, SEEK_SET, 0);
      while(!feof(Form1->fp))
      {
        sio_putch(Form1->port, ch=fgetc(Form1->fp));
        Form1->StaticText2->Caption = ++i;
      }
      fclose(Form1->fp);
    }
    catch(...)
    {
      Application->MessageBox("Can't perform one of the following file operations: Open, Seek, Read, Close.", "File Error", IDOK);
    }
}
//---------------------------------------------------------------------------
 

⌨️ 快捷键说明

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