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: 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.
这个差不多就能满足你的要求了,自己改一改就行了