首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

请问多线程,下面程序为什么会出错

2012-03-14 
请教多线程,下面程序为什么会出错?unit Unit1interfaceusesWindows, Messages, SysUtils, Variants, Clas

请教多线程,下面程序为什么会出错?
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP;

type
  TForm1 = class(TForm)
  Button1: TButton;
  IdHTTP1: TIdHTTP;
  procedure Button1Click(Sender: TObject);
  private
  procedure up;
  { Private declarations }
  public
  { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.up;
var s:string;
begin
  try
s:=idhttp1.Get('http://www.zhcw.com/data-js/nowdata98.js');出错的地方
  except
  showmessage('更新失败!');
  end;
  if s<>'' then showmessage('更新成功!');
end;

procedure TForm1.Button1Click(Sender: TObject);
var tid:dword;
begin
  CreateThread(nil,0,@tform1.up,nil,0,Tid);
end;

end.

First chance exception at $7C812A5B. Exception class EAccessViolation with message 'Access violation at address 00482985 in module 'up.exe'. Read of address 00000364'. Process up.exe (2320)

[解决办法]
用WaitForMultiObjects等待子线程结束,你创建该线程后,主线程退出,实例内存空间被释放,该子线程调用主线程的东西,当然出内存错误了

热点排行