RSS订阅 | 匿名投稿
您的位置:网站首页 > 线程 > 正文

delphi线程

作者:admin 来源:未知 日期:2010/4/29 23:56:16 人气: 标签:


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.


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: