unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 =
class(TForm)
Lv: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type TMyThread =
class (TThread)
Private
FsCap, FsSub1, FsSub2 :
string;
FLv : TListView;
procedure UpdateListView();
procedure AddLvItem (ACap,ASub1,ASub2 :
string);
protected
Procedure Execute ();
Override;
public
Constructor Create (ALv : TListView);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var MyThread : TMyThread;
begin
MyThread := TMyThread.Create(Lv);
end;
{ TMyThread }
constructor TMyThread.Create(ALv : TListView);
begin
FreeOnTerminate := false;
Flv := ALv;
inherited Create (false);
end;
procedure TMyThread.Execute;
var
i : integer;
begin
inherited;
for i:=0
to 9
do
begin
FsCap := '
Cap - ' + inttostr (i);
FsSub1 := '
Sub1 - ' + inttostr (i);
FsSub2 := '
Sub2 - ' + inttostr (i);
Synchronize(UpdateListView);
end;
Terminate;
end;
procedure TMyThread.UpdateListView;
begin
AddLvItem(FsCap,FsSub1,FsSub2);
end;
procedure TMyThread.AddLvItem(ACap, ASub1, ASub2:
string);
var
li : TListItem;
begin
li := Flv.Items.Add;
li.Caption := ACap;
li.SubItems.Add(ASub1);
li.SubItems.Add(ASub2);
end;
end.