DELPHI中运行会有类似这样的错误,
Project1.exe faulted with message: 'access violation at 0x00406761: write of address 0x01de0e08'. Process Stopped. Use Step or Run to continue.
如果直接运行程序,有时还有个提示出错了,有时什么提示也没有就退出了for i:=1 to 20 do
CreateThread(nil, 0, @CheckAcc, pointer(id), 0, dwThreadID);
procedure CheckAcc(vid:Integer);stdcall;
var
str:String;
idhttp1:TIdHTTP;
begin
try
idhttp1:=TIdHttp.Create;
str:=idhttp1.Get('http://www.163.com/');
except
idhttp1.Free;
exit;
end;
idhttp1.Free;
end;
Project1.exe faulted with message: 'access violation at 0x00406761: write of address 0x01de0e08'. Process Stopped. Use Step or Run to continue.
如果直接运行程序,有时还有个提示出错了,有时什么提示也没有就退出了for i:=1 to 20 do
CreateThread(nil, 0, @CheckAcc, pointer(id), 0, dwThreadID);
procedure CheckAcc(vid:Integer);stdcall;
var
str:String;
idhttp1:TIdHTTP;
begin
try
idhttp1:=TIdHttp.Create;
str:=idhttp1.Get('http://www.163.com/');
except
idhttp1.Free;
exit;
end;
idhttp1.Free;
end;
单独的也不会出错,多个线程同时执行就有可能出错了, 不知道该怎么办了
end
中间什么都不加试试看
THttpThread = class(TThread)
private
FVID: Integer;
protected
procedure Execute; override;
public
constructor Create(vid: Integer);
end;{ THttpThread }constructor THttpThread.Create(vid: Integer);
begin
inherited Create(true);
FreeOnTerminate := True;
FVID := vid;
Resume;
end;procedure THttpThread.Execute;
var
str: string;
idhttp1: TIdHTTP;
begin
idhttp1 := TIdHttp.Create;
try
try
str := idhttp1.Get('http://www.163.com/');
except
end;
finally
idhttp1.Free;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
for i := 1 to 20 do
begin
THttpThread.Create(i);
end;
end;
http://www.cnasm.com/view.asp?classid=61&newsid=297