delphi线程



unit Unit1;

interface

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

type
TForm1 = class(TForm)
   ListView1: TListView;
   Button1: TButton;
   procedure Button1Click(Sender: TObject);
private
   { Private }
public
   { Public }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
n: integer;
fpb: TProgressThread;
begin
n := listview1.Items.Count;
with listview1.Items.Add do
begin
   Caption := format('%d', [n]);
   update;
end;
fpb := TProgressThread.Create(False);
fpb.Index := n;
fpb.Resume;
end;

end.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

unit Unit2;

interface

uses
Classes, Types, ComCtrls;

type
TProgressThread = class(TThread)
private
   procedure progressupdate;
protected
   procedure Execute; override;
public
   Index: integer;
end;

implementation
uses Unit1;

procedure TProgressThread.Execute;
begin
// Synchronize(progressupdate);
progressupdate
end;

procedure TProgressThread.progressupdate;
var
r: TRect;
pb: TProgressBar;
i: integer;
begin
r := Form1.Listview1.Items[Index].DisplayRect(drBounds);
r.Left := r.Left + Form1.Listview1.columns[0].Width;
r.Right := r.Left + Form1.Listview1.columns[1].Width;
pb := TProgressBar.Create(nil);
pb.Visible := False;
pb.Parent := Form1.Listview1;
pb.BoundsRect := r;
pb.Position := 0;
pb.Max := 50000;
pb.Visible := True;
Form1.Listview1.Items[Index].Data := pb;
for i := 0 to 50000 do begin
   pb.Position := i;
end;
pb.Free;
end;

end.


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678