我要把这个过程放到线程里做,该如何写(最终目的可以让我能看到label1.Caption :='正在安装更新...'这个东东的进度)(20分)

  • 主题发起人 主题发起人 wp231957
  • 开始时间 开始时间
W

wp231957

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to filelistbox1.Count-1 do begin
ShellExecute(Handle, nil, PChar(filelistbox1.Items), PChar(' /quiet /norestart'), nil, SW_NORMAL);
label1.Caption :='正在安装更新...'+inttostr(i+1)+'/'+inttostr(filelistbox1.Count );
end;
showmessage('更新安装完毕');
end;
 
与主线程的同步,使用syncronize()
你可以这样:在线程类中,添加方法:
procedure UpdateLabelCaption;
begin
TForm1(Application.MainForm).Label1.Caption := '';
end;
然后
syncronize(UpdateLabelCaption);
 
syncronize怎么提示没定义
难道是需要引用什么还是拼写错了
 
//主程序,还是有问题,请帮忙看看,编译都通不过
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, FileCtrl, ComCtrls;

type
TForm1 = class(TForm)
FileListBox1: TFileListBox;
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
filelistbox1.Directory :='update';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
thread:update;
begin
thread:=update.execute(false);
end;

end.
//////////////////////////////////////////////////////////////
线程部分
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, FileCtrl, ComCtrls,unit1;

type
update = class(TThread)
private
{ Private declarations }
procedure updatelabelcaption;
protected
procedure Execute; override;
end;

implementation
var
i:integer;
{ update }
procedure update.updatelabelcaption;
begin
TForm1(Application.MainForm).Label1.Caption :='正在安装更新...'+inttostr(i+1)+'/'+inttostr(form1.filelistbox1.Count );
end;

procedure update.Execute;
begin
for i:=0 to form1.filelistbox1.Count-1 do begin
ShellExecute(Handle, nil, PChar(form1.filelistbox1.Items), PChar(' /quiet /norestart'), nil, SW_NORMAL);
synchronize(UpdateLabelCaption);
end;
showmessage('更新安装完毕');
end;

end.
 
不用这样做! 使用一个Tform就可以实现你那样的效果了
 
能帮忙修改一下吗,谢谢
 
穷死了,要分
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
699
import
I
后退
顶部