当前位置:百问十五>生活百科>delphi中用 CreateThread()老提示[错误] Unit1.pas(153): Variable required

delphi中用 CreateThread()老提示[错误] Unit1.pas(153): Variable required

2024-08-22 17:04:53 编辑:join 浏览量:599

delphi中用 CreateThread()老提示[错误] Unit1.pas(153): Variable required

贴上你的源码吧,@geturl是你写的一个过程吧?

如果不想贴,给你个例子吧

var

Form1: TForm1;

ThreadHandle: THandle; // holds the handles the threads

ThreadHandle2: THandle;

CriticalSection: TRTLCriticalSection; // holds the critical section info

implementation

{$R *.DFM}

function ThreadFunc(Info: Pointer): Integer; stdcall;

var

Count : Integer; // general loop control variable

begin

{performing the EnterCriticalSection function prevents the second thread

from executing until this thread leaves the critical section}

EnterCriticalSection(CriticalSection);

{show a visual display}

for Count := 0 to 100 do

begin

Form1.Edit1.Text := IntToStr(Count);

end;

{display a message}

Form1.Edit1.Text := 'Hello from the thread!';

{pause for a second}

Sleep(1000);

{leave the critical section and exit the thread}

LeaveCriticalSection(CriticalSection);

ExitThread(4);

end;

procedure TForm1.Button1Click(Sender: TObject);

var

ThreadId1, ThreadId2: DWORD; // holds the created thread identifiers

begin

{initialize the critical section information}

InitializeCriticalSection(CriticalSection);

{create and execute the first thread}

ThreadHandle := CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId1);

{create and execute the second thread}

ThreadHandle2 := CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId1);

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

{we are done, so destroy the critical section information}

DeleteCriticalSection(CriticalSection);

end;

标签:delphi,CreateThread,Unit1

版权声明:文章由 百问十五 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.baiwen15.com/life/248066.html
热门文章