如何在Label中显示OpenDialog打开的文件名!但不显示路径名! (50分)

  • 主题发起人 火凤凰一
  • 开始时间

火凤凰一

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(]我想用OpenDialog打开文件,用LABEL显示其文件名,但不显示它的文件路径,请问各位大哥要怎样做?
谢谢!
 
可以用ExtractFilePath( PathName )获取其路径,然后路径文件名减去它就行了。
呵呵,笨办法。
 
不会吧?
用ExtractFileName就行了。
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Label1.Caption := ExtractFileName(OpenDialog1.FileName);
end;
 
You might even try the following function to manipulate the returning string
from OpenDialog box, though it's a bit clumsy, and obviouly not the best way.
function strPro(s:string) : string;
var
i : integer;
pos : integer;
len : integer;
begin
s :=trim(s);
len :=length(s);
i :=len;
while i>0do
begin
if copy(s,i,1)='/' then
begin
pos:=i;
i:=1;
end;
i:=i-1;
end;
s:=copy(s,pos+1,len-pos);
result:=s;
end;

procedure TForm1.btnGoClick(Sender: TObject);
var
s : string;
i : integer;
p : integer;
l : integer;
begin
openDialog1.Execute;
s:=openDialog1.FileName;
s := strPro(s);
label1.Caption:=s;
end;
 
ExtractFilePath( PathName )就可以搞定 了。
 
ExtractFileName
 
应该在opendialog的属性里面就可以设置好的确
 
Label1.Caption := ExtractFilePath(OpenDialog1.FileName);
 
多人接受答案了。
 

Similar threads

回复
0
查看
679
不得闲
D
回复
0
查看
753
DelphiTeacher的专栏
D
D
回复
0
查看
729
DelphiTeacher的专栏
D
D
回复
0
查看
844
DelphiTeacher的专栏
D
顶部