请帮我看看下面的代码哪儿有问题(50分)

  • 主题发起人 主题发起人 AI_Player
  • 开始时间 开始时间
A

AI_Player

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

MyThread = class(TThread)
private
{ Private declarations }
i:integer;
public
constructor Create(ord:integer);
protected
procedure Execute;
override;
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
constructor MyThread.Create(ord:integer);
begin
inherited Create(false);
i:=ord;
FreeOnTerminate:=true;
end;

procedure MyThread.Execute;
begin
{ Place thread code here }
showmessage(inttostr(i));
end;

procedure TForm1.Button1Click(Sender: TObject);
var j:integer;
begin
for j:=1 to 10do
MyThread.Create(j);
end;

end.
 
showmessage要同步,用synchronize.
 
是要用syncronize,但参数i没办法出来.
 
procedure MyThread.Execute;
begin
synchronize(MyshowMessage);
end;
procedure Mythread.MyshowMessage;
begin
showmessage(inttostr(i));
end;
 
应该是
procedure Mythread.MyshowMessage;
begin
showMessage(IntToStr(MyThread.i))
end;
 
re LeeChange:对不起了,你的代码通不过耶.
 
后退
顶部