急~~~~~~~~~~~~~~~~~~~~~(50分)

  • 主题发起人 主题发起人 shell~
  • 开始时间 开始时间
S

shell~

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个播放器
我想用opendialog来打开文件并把所选中的文件显示在memo框中
但是为什么我每次只能选中一个不能实现全选呢
哪位大虾帮忙一下
还有我想在memo中只显示歌曲文件名而不显示路径名
歌曲的链接又要如何实现
 
ExtractFileName(opendialog1.FileName)
 
TOpenDialog的Options属性中的ofAllowMultiSelect设为True即可。
 
ExtractFileName函数为分解得到文件名,如
ExtractFileName('c:/aaa/bbb/test.txt');
===> test.txt !!
 
ExtractFileName(opendialog1.FileName)
Files[0] = Files[n]
 
多选:Options := [ofAllowMultiSelect];
取文件名:for i := 0 to Files.count -1do

memo1.lines.add(ExtractFileName(Files))
 
ofAllowMultiSelect->True
 
多谢上面各位朋友
你们能不能告诉我如何实现歌曲的链接
 
用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.

 
楼上的兄弟是不是误解了
我是想双击播放歌曲
 
响应TLISTBOX的OnDblClick事件。
 
MultiSelect设为TRUE,在把OPTION中的与它相同属性的选上。
createdirectoryex()可以显示路径。
 
后退
顶部