读书人

线程引发access violation的异常

发布时间: 2012-04-07 17:31:51 作者: rapoo

线程引发access violation的错误

Delphi(Pascal) code
//连接FTP的procedure TFtpThread.Execute;begin  FreeOnTerminate := True;  if not FtpConnState then  begin    FtpConnState := ConnFtp(MainForm.FtpLibrary,UserName,PassWord);    SendMessage(MainForm.Handle,WM_CONNFTP,Integer(PChar(FtpConnState)),0);  end;end;//上传文件的procedure TUpLoadThread.Execute;begin  FreeOnTerminate := True;   if not FtpConnState then  begin    MainForm.FtpLibrary.RemotePath :='446\1.txt';    MainForm.FtpLibrary.LocalPath:='c:\1.txt';    MainForm.FtpLibrary.Upload;  end;end;

上面的FtpLibrary是一个主窗体上的OCX控件 如果在主线程中直接调用没问题 放在线程里就不行了就会报access violation at address in module 'MSVBVM60.DLL'错误



[解决办法]
在线程离创建FtpLibrary

读书人网 >.NET

热点推荐