谁帮我看看这段代码哪儿错了(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;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

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

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

procedure MyThread.Execute;
begin
while k<100do
begin
synchronize(show);
k:=k+1;
end;
end;

procedure MyThread.show;
begin
{ Place thread code here }
form1.Memo1.Lines:=inttostr(i)+': '+inttostr(k);
end;

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

end.
 
程序运行是对的,但你的目的是什么?
//form1.Memo1.Lines.add(inttostr(i)+': '+inttostr(k));是这样吗?
 
是在memo1中,有十行分别从0计数到99
但运行后只有前两行
 
Memo1.Lines开始只有两行,所以对memo1.Lines的赋值在i>1时无意义.
先在Memo1.Lines属性中加几个回车吧.
 
如何在程序中完成?
 
procedure MyThread.show;
begin
{ Place thread code here }
if i>=Form1.Memo1.Lines.Count then
Form1.Memo1.Lines.Append('');
form1.Memo1.Lines:=inttostr(i)+': '+inttostr(k);
end;
 
后退
顶部