S
student_541
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CriticalSection: TRTLCriticalSection;
implementation
{$R *.DFM}
function ThreadFunc(Info: Pointer): Integer;
stdcall;
var
Count,i: Integer;
begin
EnterCriticalSection(CriticalSection);
Form1.Button1.Enabled:=False;
for Count := 0 to 10000do
begin
Form1.Edit1.Text := IntToStr(Count);
end;
Form1.Edit1.Text := '线程结束';
Sleep(500);
Form1.Button1.Enabled:=true;
LeaveCriticalSection(CriticalSection);
ExitThread(4);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ThreadId1, ThreadId2: DWORD;
begin
Button1.Enabled:=false;
if CriticalSection.RecursionCount<>0 then
DeleteCriticalSection(CriticalSection);
InitializeCriticalSection(CriticalSection);
CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId1);
CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId2);
end;
end.
这是一本书上的源代码,我的问题是
1,我记得delphi中所有的函数或过程都要先声明,可是function ThreadFunc(Info: Pointer): Integer;
stdcall;
却没有申明?为什么?
2,我查了ExitThread函数的意思是中止线程,参数可由getexitcodethread获得,
可这里却用4代替了,我将它改为任意的值都可以,是不是这个值没有什么意义,
请大哥们指点。
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CriticalSection: TRTLCriticalSection;
implementation
{$R *.DFM}
function ThreadFunc(Info: Pointer): Integer;
stdcall;
var
Count,i: Integer;
begin
EnterCriticalSection(CriticalSection);
Form1.Button1.Enabled:=False;
for Count := 0 to 10000do
begin
Form1.Edit1.Text := IntToStr(Count);
end;
Form1.Edit1.Text := '线程结束';
Sleep(500);
Form1.Button1.Enabled:=true;
LeaveCriticalSection(CriticalSection);
ExitThread(4);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ThreadId1, ThreadId2: DWORD;
begin
Button1.Enabled:=false;
if CriticalSection.RecursionCount<>0 then
DeleteCriticalSection(CriticalSection);
InitializeCriticalSection(CriticalSection);
CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId1);
CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId2);
end;
end.
这是一本书上的源代码,我的问题是
1,我记得delphi中所有的函数或过程都要先声明,可是function ThreadFunc(Info: Pointer): Integer;
stdcall;
却没有申明?为什么?
2,我查了ExitThread函数的意思是中止线程,参数可由getexitcodethread获得,
可这里却用4代替了,我将它改为任意的值都可以,是不是这个值没有什么意义,
请大哥们指点。