DirectoryListBox目录选择问题

本文探讨了在使用Delphi的DirectoryListBox组件时遇到的问题,包括如何避免在选择无光盘驱动器时出现的IO ERROR,以及如何将当前选择的目录路径显示在编辑框中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DirectoryListBox目录选择问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061207225847227.html
我用DriveComboBox来控制DirectoryListBox的driver。  
  当选择了没有放光盘的光驱时,就会报IO   ERROR。  
  怎么避免这个问题啊?  
  我看见一些程序在选择驱动器的时候,选中没有光盘的光驱时会失效的,怎么实现呢?  
 

还有,如何把DirectoryListBox中当前选择的目录路径显示到一个编辑框里面啊?

顶一下

http://community.youkuaiyun.com/Expert/topic/5165/5165787.xml?temp=4.690188E-02

谢谢

转载于:https://www.cnblogs.com/delphi2007/archive/2009/02/11/1388381.html

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl, IdBaseComponent, ShellApi,IdComponent, IdIPWatch, ExtCtrls, jpeg; type TForm1 = class(TForm) FileListBox1: TFileListBox; Button1: TButton; DirectoryListBox1: TDirectoryListBox; DriveComboBox1: TDriveComboBox; FilterComboBox1: TFilterComboBox; Edit1: TEdit; Label1: TLabel; Button2: TButton; Label2: TLabel; Memo1: TMemo; Label3: TLabel; IdIPWatch1: TIdIPWatch; Label4: TLabel; Button3: TButton; Edit2: TEdit; Label5: TLabel; Label6: TLabel; Label7: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FileListBox1DblClick(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Label3Click(Sender: TObject); procedure Label4Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; a1:integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var str5: string; begin begin str5 := InputBox('输入姓名', 'Name:', ''); // Application.Terminate; // 退出程序 if str5 ='' then showmessage('没有输入姓名,请重新输入') else begin ShowMessage(str5); //显示输入的内容 CopyFile(pchar(string(FileListBox1.FileName)), pchar('\\10.10.3.167\stu\' + str5+copy(IdIPWatch1.LocalIP,9,3)+Edit1.text), false); Application.MessageBox('已经复制到老师机子里了', '提示', MB_OK) // Application.Terminate; // 退出程序 end ; end; end; procedure TForm1.FormCreate(Sender: TObject); begin self.FileListBox1.FileEdit :=self.Edit1 ; self.FilterComboBox1.FileList :=self.FileListBox1 ; self.DirectoryListBox1.FileList :=self.FileListBox1 ; self.DirectoryListBox1.DirLabel :=self.Label1 ; self.DriveComboBox1.DirList :=self.DirectoryListBox1 ; self.Button1.Default :=true; self.Button3.Visible :=false; end; procedure TForm1.FileListBox1DblClick(Sender: TObject); begin // CopyFile(FileListBox1.FileName,FileListBox1.FileName,False); //CopyFile(pchar(string(FileListBox1.FileName)), pchar('\\10.10.3.167\stu\' +copy(IdIPWatch1.LocalIP,9,3)+ Edit1.text), false); //Application.MessageBox('已经复制到老师机子里了', '提示', MB_OK) ShellExecute(handle,'open', pchar(string(FileListBox1.FileName)), nil, nil, SW_SHOWNORMAL); end; procedure TForm1.Button2Click(Sender: TObject); begin Application.Terminate; // 退出程序 end; procedure TForm1.Label3Click(Sender: TObject); begin memo1.Lines.LoadFromFile(getcurrentdir+'\a.txt'); end; procedure TForm1.Label4Click(Sender: TObject); begin memo1.Lines.LoadFromFile(getcurrentdir+'\a1.txt'); end; procedure TForm1.Button3Click(Sender: TObject); var str6: string; begin begin str6 := InputBox('输入窗口标题', '输入提示', '默认输入内容'); ShowMessage(str6); //显示输入的内容 memo1.Lines.SaveToFile('\\10.10.3.167\stu\' + copy(IdIPWatch1.LocalIP,9,3)+str6+'.txt'); Application.MessageBox('你的作业已经复制到老师机子里了', '提示', MB_OK) end; end; end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值