为什么我批量产生的线程--传入的数据都变成了最后一次的那个?详情进来看看,很奇怪
cclq 2005-03-21 04:03:59 public
constructor Create(InputStringList:TStringList);
..........
constructor TMyThread.Create(InputStringList:TStringList);
begin
inherited Create(True);
FString:=InputStringList;
使用的时候:
var
I : integer
TempThread: TMyThread;
ThreadPoint:string;
TempThreadName:string;
begin//启动线程 完成ThreadId(Point)的产生。
for I := 0 to 9 do
begin
Msg[0]:=IntToStr(I);
TempThread := TMyThread.Create(Msg);//Msg是一个传入的变量,
ThreadPoint := IntToStr(Integer(TempThread));
TempThreadName:=ThreadPoint;
MyThreadList.AddObject( ThreadPoint, TempThread);
//MyThreadList 是一个全局变量,控制线程的。
end;
到这里完成线程创建,线程创建后是挂起的// inherited Create(True);
用
function TThreadManager.StartScan: boolean;
var
I: Integer;
begin
Result := False;
if MyThreadList.Count = 0 then exit;
for I := 0 to MyThreadList.Count-1 do
begin
Result := True;
TMyThread(StrToInt(MyThreadList[I])).Resume;//在这里统一运行线程
end;
end;
结果,发现,在线程的产程的数据出现了问题,10个线程里面的有关Msg[0] 的数据全部是 9