idhttp1在线程中为啥会出错啊?

fbiboss 2012-02-01 03:54:47
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;
...全文
119 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pathletboy 2012-02-01
  • 打赏
  • 举报
回复
如果你不想用TThread那就用BeginThread代替CreateThread吧。
pathletboy 2012-02-01
  • 打赏
  • 举报
回复
另外补充个关于Delphi中CreateThread的资料。
http://www.cnasm.com/view.asp?classid=61&newsid=297
pathletboy 2012-02-01
  • 打赏
  • 举报
回复
用TThread似乎没啥问题。

type
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;
erhan 2012-02-01
  • 打赏
  • 举报
回复
except与
end
中间什么都不加试试看
fbiboss 2012-02-01
  • 打赏
  • 举报
回复
就是GET出错啊,不加这个就不会出错,
单独的也不会出错,多个线程同时执行就有可能出错了, 不知道该怎么办了
bdmh 2012-02-01
  • 打赏
  • 举报
回复
你跟踪一下吧,看看错误是怎么出现的,是get出错还是啥的

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧