#include <vcl.h>
#pragma hdrstop
#include "Thread.h"
#include "SFmain.h"
#include "card.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 Unit1::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TMyThread::TMyThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{
while (!Terminated)
{
Synchronize(MyRead);
}
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::MyRead()
{
get = genReadCard(TollMain->hComDev,20,0,8,TollMain->carddata);
//读卡代码
if (get==0)
{
TollMain->IC_Number = TollMain->carddata;
TollMain->IC_Number = TollMain->IC_Number.SubString(1,8);
TollMain->Edit1->Text = TollMain->IC_Number;
TollMain->ListBox1->Items->Add(TollMain->IC_Number);
}
Sleep(20);
}
调用:
IC_Thread = new TMyThread(false);//非接触式IC卡
关闭:
IC_Thread->Terminate();
//非接触式IC卡