置一个boolean型全局变量,想终止线程时置全局变量为flase,在你的线程中检查那个全局变量
为flase时退出不就行了吗
为flase时退出不就行了吗
解决方案 »
- 散分二
- 能不能用edit里的内容做变量依据?
- delphi 编写的com 组件的兼容性问题。
- 我可不可以用Ado或BDE直接去连接linux上的oracle数据库!
- 100分紧急求救!!!!!
- 三次提问
- 哪位高手能够比较客观的给小弟讲讲vb与delphi之间在数据开发中那个更好一点,为什么?
- 这是什么病毒?其启动怎么在MsConfig删除不了的?
- 请教一个关于数据库的问题
- 以前写的MIS系统一般多是通过菜单进入某个功能,现在比较流行的除了菜单外,还有。。。,不知是什么控件
- 各位大师:为什么我的delphi5打了补丁后仍报错:bof或eof有一个是'真'...错误,提出解决方案及彻底解决重重奖励
- 这句SQL怎么写?简单!
{
CHAR ch = 'A'; hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); /* Get display screen's text row and column information. */
GetConsoleScreenBufferInfo( hStdOut, &csbi ); /* Launch CheckKey thread to check for terminating keystroke. */
_beginthread( CheckKey, 0, NULL ); /* Loop until CheckKey terminates program. */
while( repeat )
{
/* On first loops, launch character threads. */
_beginthread( Bounce, 0, (void *) (ch++) ); /* Wait one second between loops. */
Sleep( 1000L );
}
}/* CheckKey - Thread to wait for a keystroke, then clear repeat flag. */
void CheckKey( void *dummy )
{
_getch();
repeat = 0; /* _endthread implied */}/* Bounce - Thread to create and and control a colored letter that moves
* around on the screen.
*
* Params: ch - the letter to be moved
*/
void Bounce( void *ch )
{
/* Generate letter and color attribute from thread argument. */
char blankcell = 0x20;
char blockcell = (char) ch;
BOOL first = TRUE;
COORD oldcoord, newcoord;
DWORD result;
/* Seed random number generator and get initial location. */
srand( _threadid );
newcoord.X = GetRandom( 0, csbi.dwSize.X - 1 );
newcoord.Y = GetRandom( 0, csbi.dwSize.Y - 1 );
while( repeat )
{
/* Pause between loops. */
Sleep( 100L ); /* Blank out our old position on the screen, and draw new letter. */
if( first )
first = FALSE;
else
WriteConsoleOutputCharacter( hStdOut, &blankcell, 1, oldcoord, &result );
WriteConsoleOutputCharacter( hStdOut, &blockcell, 1, newcoord, &result ); /* Increment the coordinate for next placement of the block. */
oldcoord.X = newcoord.X;
oldcoord.Y = newcoord.Y;
newcoord.X += GetRandom( -1, 1 );
newcoord.Y += GetRandom( -1, 1 ); /* Correct placement (and beep) if about to go off the screen. */
if( newcoord.X < 0 )
newcoord.X = 1;
else if( newcoord.X == csbi.dwSize.X )
newcoord.X = csbi.dwSize.X - 2;
else if( newcoord.Y < 0 )
newcoord.Y = 1;
else if( newcoord.Y == csbi.dwSize.Y )
newcoord.Y = csbi.dwSize.Y - 2; /* If not at a screen border, continue, otherwise beep. */
else
continue;
Beep( ((char) ch - 'A') * 100, 175 );
}
/* _endthread given to terminate */
_endthread();
}
定义全局变量
stop : boolean;
初值哈哈:false;
procedure TtestThread.Execute;
{
FreeOnTerminate := true;
while (not stop) do
............................................
}
procedure TFormMain.SpeedButton15Click(Sender: TObject);
begin
stop := true;
end;