Главная » Delphi » Компоненты » Добавление данных в TListView

Добавление данных в TListView

19:43
unit frmMain;
 
interface
 
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,shellapi;
type
PMyRec = ^TMyRec;
TMyRec = record
path: string;
//...
end;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure ListView1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
 
var
Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
var
ListItem:TListItem;
MyRec:PMyRec;
begin
if OpenDialog1.Execute then begin
ListItem:=ListView1.Items.Add;
ListItem.Caption:=extractfilename(OpenDialog1.FileName);
new(MyRec);
MyRec^.path:=OpenDialog1.FileName;
//MyRec^....
ListItem.Data:=MyRec;
end;
end;
 
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
i:integer;
begin
for i:=0 to ListView1.Items.Count-1 do
Dispose(PMyRec(ListView1.Items[i].Data));
end;
 
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
shellexecute(handle,'open',pchar(PMyRec(ListView1.Selected.Data)^.path),
'','',SW_SHOWNORMAL);
end;
 
end.