begin Thread 函数问题(10分)

  • 主题发起人 主题发起人 紫竹林23424
  • 开始时间 开始时间

紫竹林23424

Unregistered / Unconfirmed
GUEST, unregistred user!
unit frm_begin
Thread;
http://v.ku6.com/show/LctRYoKchfqCdhu3.html
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TFrmbegin
Thread = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
LbCount: TLabel;
LBCount2: TLabel;
Button1: TButton;
Bevel1: TBevel;
procedure Button1Click(Sender: TObject);
private
//function ThreadRun(Parameter: Pointer): Integer;
{ Private declarations }
public
{ Public declarations }
end;

var
Frmbegin
Thread: TFrmbegin
Thread;
implementation
{$R *.dfm}
function ThreadRun(Parameter: Pointer): Integer;
//声明函数,格式必须如此
var
i:integer;
//用于去值范围
begin
for i:=0 to 1000do
//循坏取值范围在0到1000
begin
Frmbegin
Thread.LbCount.Caption:=inttostr(i);
//在标签内显示i的数字
sleep(100);
//停止1妙
end;
end;

function ThreadRun2(Parameter: Pointer): Integer;
var
i:integer;
begin
for i:=0 to 1000do
begin
Frmbegin
Thread.LbCount2.Caption:=inttostr(i);
sleep(200);
end;
end;

[red]//下面是问题[/red]
procedure TFrmbegin
Thread.Button1Click(Sender: TObject);
var
s:TThreadFunc;

ID,ID2:cardinal;

begin
ID:=1001;
// 不知道什么意思
ID2:=ID+1;
// 同上
begin
Thread(nil,0,ThreadRun,nil,1002,ID);
begin
Thread(nil,0,ThreadRun2,nil,1002,ID2);
end;

end.

//请高手解答
 
ID:=1001;

ID2:=ID+1;
多余的
 
我都是用CreateThread
begin
Thread是你自己的函数?
 
begin
Thread不是我自定义的函数.
 
begin
Thread最后一个参数是threadid,每启动一个thread都会有自己的唯一ID,begin
Thread调用成功后这个id会写入最后一个参数中
所以ID:=1001;ID2:=ID+1;这2句没有必要
 
{$IFDEF MSWINDOWS}
function begin
Thread(SecurityAttributes: Pointer;
StackSize: LongWord;
ThreadFunc: TThreadFunc;
Parameter: Pointer;
CreationFlags: LongWord;
var ThreadId: LongWord): Integer;
var
P: PThreadRec;
begin
New(P);
P.Func := ThreadFunc;
P.Parameter := Parameter;
IsMultiThread := TRUE;
Result := CreateThread(SecurityAttributes, StackSize, @ThreadWrapper, P,
CreationFlags, ThreadID);
end;

procedure EndThread(ExitCode: Integer);
begin
ExitThread(ExitCode);
end;
{$ENDIF}
{$IFDEF LINUX}
function begin
Thread(Attribute: PThreadAttr;
ThreadFunc: TThreadFunc;
Parameter: Pointer;
var ThreadId: Cardinal): Integer;
var
P: PThreadRec;
begin
if Assigned(begin
ThreadProc) then
Result := begin
ThreadProc(Attribute, ThreadFunc, Parameter, ThreadId)
else
begin
New(P);
P.Func := ThreadFunc;
P.Parameter := Parameter;
IsMultiThread := True;
Result := _pthread_create(ThreadID, Attribute, @ThreadWrapper, P);
end;
end;

procedure EndThread(ExitCode: Integer);
begin
if Assigned(EndThreadProc) then
EndThreadProc(ExitCode);
// No "else
" required since EndThreadProcdo
es not (!!should not!!) return.
_pthread_detach(GetCurrentThreadID);
_pthread_exit(ExitCode);
end;
{$ENDIF}
hs-kill,讲得是对的。
 
接受答案了.
 

Similar threads

I
回复
0
查看
610
import
I
I
回复
0
查看
782
import
I
I
回复
0
查看
696
import
I
I
回复
0
查看
842
import
I
后退
顶部