G
grj1
Unregistered / Unconfirmed
GUEST, unregistred user!
单击stop,总是报内存冲突错误
单元A:
var
I:Integer;
procedure TMyThread.Execute;
begin
I:=0;
while not terminateddo
begin
Synchronize(ShowData);
sleep(100);
I:=I+1;
end;
end;
procedure TMyThread.ShowData;
begin
Form1.Memo1.Lines.Add(IntToStr(I));
end;
单元B(窗体):
procedure TForm1.Button1Click(Sender: TObject);
var
myt:TMyThread;
begin
if Button1.caption='start' then
begin
begin
myt:= TMyThread.Create(true);
myt.FreeOnTerminate:=true;
myt.Resume;
Button1.caption:='stop';
end;
end
else
begin
myt.Terminate;
Button1.caption:='start';
end;
end;
单元A:
var
I:Integer;
procedure TMyThread.Execute;
begin
I:=0;
while not terminateddo
begin
Synchronize(ShowData);
sleep(100);
I:=I+1;
end;
end;
procedure TMyThread.ShowData;
begin
Form1.Memo1.Lines.Add(IntToStr(I));
end;
单元B(窗体):
procedure TForm1.Button1Click(Sender: TObject);
var
myt:TMyThread;
begin
if Button1.caption='start' then
begin
begin
myt:= TMyThread.Create(true);
myt.FreeOnTerminate:=true;
myt.Resume;
Button1.caption:='stop';
end;
end
else
begin
myt.Terminate;
Button1.caption:='start';
end;
end;