用ListBox代替Memo,
关于歌曲名的链接代码如下(双击可显示歌曲名):
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
ListBox1: TListBox;
procedure Memo1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Type
TFileName=Class
private
FFileName:String;
Public
constructor Create(sFileName:String);
Property FileName:String Read FFileName Write FFileName;
end;
procedure TForm1.Memo1DblClick(Sender: TObject);
Var TmpFileName:TFileName;
begin
if ListBox1.ItemIndex>0 then
begin
TmpFileName:=TFileName(ListBox1.Items.Objects[ListBox1.ItemIndex]);
ShowMessage(TmpFileName.FileName);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OpenDialog1.Options:=OpenDialog1.Options+[ofAllowMultiSelect,ofPathMustExist,ofFileMustExist,ofEnableSizing];
ListBox1.Clear;
end;
{ TFileName }
constructor TFileName.Create;
begin
inherited Create;
FFileName:=sFileName;
end;
procedure TForm1.Button1Click(Sender: TObject);
Var i:Integer;
TmpFileName:TFileName;
s:String;
begin
if OpenDialog1.Execute then
begin
For i:=0 to OpenDialog1.Files.Count-1do
begin
s:=OpenDialog1.Files;
TmpFileName:=TFileName.Create(s);
ListBox1.Items.AddObject(ExtractFileName(s),TmpFileName);
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
Var i:Integer;
TmpFileName:TFileName;
begin
For i:=0 to ListBox1.Items.Count-1do
begin
TmpFileName:=TFileName(ListBox1.Items.Objects);
TmpFileName.Free;
end;
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
Var TmpFileName:TFileName;
begin
if ListBox1.ItemIndex>0 then
begin
TmpFileName:=TFileName(ListBox1.Items.Objects[ListBox1.ItemIndex]);
ShowMessage(TmpFileName.FileName);
end;
end;
end.