关于DriveComboBox问题???当我选择a盘时a盘没有软盘,弹出i/o错误!我用try except捕获异常不行啊~求救!

fbincrazy 2004-11-08 04:29:56
如题
...全文
138 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Denie_1980 2004-11-08
  • 打赏
  • 举报
回复
你的代码的问题,无聊!根异常没有关系,初始化下DriveComboBox1看看.
ghy412 2004-11-08
  • 打赏
  • 举报
回复
直接运行也捕获不了异常??? 这可真是怪了! 你的代码呢? 肯定是代码有问题!
Frank.WU 2004-11-08
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FileCtrl, StdCtrls;

type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
procedure DriveComboBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
DriverName:Char;

implementation

{$R *.dfm}
function DiskInDrive(Drive: Char): Boolean;
var ErrorMode: word;
begin
//將字母轉為大寫
if Drive in ['a'..'z'] then Dec(Drive, $20);
//確認參數為字母
if not (Drive in ['A'..'Z']) then
raise EConvertError.Create('Not a valid drive ID');
//觸發異常
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
try
if DiskSize(Ord(Drive) - $40) = -1 then
Result := False
else
Result := True;
finally
SetErrorMode(ErrorMode);
end;
end;
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
DriveComboBox1.OnChange := nil; //加入这行
if DiskInDrive(DriveComBoBox1.Drive ) then
showmessage('Driver Ready.')
else
showmessage('Driver Not Ready.');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DriveComboBox1.OnChange := nil;//加入这行
end;

procedure TForm1.FormShow(Sender: TObject);
begin
DriveComboBox1.OnChange := Form1.DriveComboBox1Change;
end;

procedure TForm1.DriveComboBox1Click(Sender: TObject);
begin
DriveComboBox1.OnChange := Form1.DriveComboBox1Change;
end;
fbincrazy 2004-11-08
  • 打赏
  • 举报
回复
呵呵我没有写一个代码 就是把DirectoryListBox1控件和DriveComboBox1控件关联起来
然后选择没有 装软盘的的a盘,结果就报错误,用try except 都捕获不到异常!
kuki84 2004-11-08
  • 打赏
  • 举报
回复
要调ide设置的,调哪儿忘的了。
budded 2004-11-08
  • 打赏
  • 举报
回复
hehe, 没问题啊
dyf2001 2004-11-08
  • 打赏
  • 举报
回复
我的怎么不报错误。是其他代码引起的吧,贴出你代码
fbincrazy 2004-11-08
  • 打赏
  • 举报
回复
不行啊。直接运行还是弹出的英文异常错误。我加了 try except 还是那样。
gobiz 2004-11-08
  • 打赏
  • 举报
回复
调试的时候try except捕获异常会失效!直接运行程序应该就可以正常捕获了!
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.

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧