困惑了,哪些组件是线程安全的呀?
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.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 TTest::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TTest::TTest(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TTest::Execute()
{
//---- Place thread code here ----
int Count=0;
while(!Terminated)
{
Count++;
Form1->Caption = "Updated in a thread" + IntToStr(Count);
Form1->Button1->Caption = IntToStr(Count);
}
}
//---------------------------------------------------------------------------
如果这样写代码,并且只有一个线程在运行,我感觉是不会有问题的.
实际上,我们很多线程都是这个作用,无非是让界面可以响应用户的操作并反映过程中的变化,
所以,我觉得这么写应该没有问题,不知道大家的意见怎么样?

