当前位置:主页>销售管理软件> 列表

求解一个简单的try...except语句!!!

记账软件版1楼: 我在edit1里输入一个文件目录,例如C:\,则在DirectoryListBox1中显示目录,但若不存在这个盘符,例如H:\,那要怎样使用try...except语句,还是使用一个判断语句呢??
望指教,谢谢!
procedure TForm1.Button1Click(Sender: TObject);
var
driver:string;
begin

driver:=edit1.Text;
DirectoryListBox1.Directory:=driver;

end;

2楼: 使用判断语句:
if DirectoryExists(edit1.Text) then
DirectoryListBox1.Directory:=driver; 如金蝶财务软件免费版

3楼: procedure TForm1.Button1Click(Sender: TObject);
var
driver:string;
begin
try
driver:=edit1.Text;
DirectoryListBox1.Directory:=driver;
except
showmessage(''error'');
end;


end;

4楼: To 骷髅头,
我试过这句,不行的!!
第一楼的可以,但有没有用try ...except语句的呢??

5楼: 为何一定要用try 。。except吗?
一般就是用yzxcsw的做法啊。

6楼: 就是用yzxcsw的方法 ,判断目录名是否存在

记账软件版7楼: 判断目录是否存在应该使用
DirectoryExists(Path)
而不是看有没有输入路径

8楼: if DirectoryExists(edit1.Text) then
DirectoryListBox1.Directory:=driver
else begin
Showmessage(''该路经不存在'');
Exit;
end;