delphi的线程调用

genispan 2008-04-14 10:52:37
我要在线程中调用如下函数,但提示出错:

function TForm1.NewThread(P:pointer):Longint;stdcall;
Var
FilesExtracted: Integer;
Begin
UnZip1.OverwriteMode:= omOverwrite;
UnZip1.ArchiveFile := Edit3.Text; // archive filename
UnZip1.ConfirmOverwrites := false; // default = False
UnZip1.RecurseDirs :=true; // default = False
UnZip1.FileSpec.Clear(); //
UnZip1.FileSpec.Add('*.*'); // *.* = extract all
UnZip1.ExtractDir := Edit5.Text; //
If DirectoryExists(Edit5.Text) Then // if the directory exists then extract
Begin
FilesExtracted := UnZip1.Extract();
ShowMessage('Files Extracted: ' + IntToStr(FilesExtracted));
End
Else
Begin
ShowMessage('Extract dir not defined');
Exit;
End;
end;

调用线程的代码:

Cthread:=CreateThread(nil,0,@TForm1.NewThread,nil,0,Tid);

希望达人帮看看 谢谢了!!
...全文
103 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Corn1 2008-04-14
  • 打赏
  • 举报
回复
把NewThread改成公用过程,不要作为Form1的成员。
ice241018 2008-04-14
  • 打赏
  • 举报
回复
function TForm1.NewThread(P:pointer):Longint;stdcall;
Var
FilesExtracted: Integer;
UnZipDemo:TUnZip;
Begin
UnZipDemo:=TUnZip.Create(self);
UnZipDemo.OverwriteMode:= omOverwrite;
UnZipDemo.ArchiveFile := sourcefile; // archive filename
UnZipDemo.ConfirmOverwrites := false; // default = False
UnZipDemo.RecurseDirs :=true; // default = False
UnZipDemo.FileSpec.Clear(); //
UnZipDemo.FileSpec.Add('*.*'); // *.* = extract all
UnZipDemo.ExtractDir := destination; //
If DirectoryExists(destination) Then // if the directory exists then extract
Begin
FilesExtracted := UnZipDemo.Extract();

ShowMessage('Files Extracted: ' + IntToStr(FilesExtracted));
End
Else
Begin
ShowMessage('Extract dir not defined');
Exit;
End;
genispan 2008-04-14
  • 打赏
  • 举报
回复
up

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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