如何產生Form的這個事件 |
尚未結案
|
kool0318
一般會員 發表:14 回覆:17 積分:6 註冊:2005-01-11 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
看不懂您的問題
是指動態產生 TApplicstionEvent 元件嗎?
那試試:
var AppEvents: TApplicationEvents; procedure TForm1.FormCreate(Sender: TObject); begin AppEvent := TApplication.Events.Create(Self); AppEvent.OnException := ApplicationEvent1Exception; end;如果不用元件的話: procedure TForm1.FormCreate(Sender: TObject); begin Application.OnException := ApplicationEvent1Exception; end;兩者都要先將 procedure TForm1.ApplicationEvents1Exception(Sender: TObject;E: Exception); 這部份做好. |
kool0318
一般會員 發表:14 回覆:17 積分:6 註冊:2005-01-11 發送簡訊給我 |
不好意思,問的不清不楚的,我再重新描述我的問題
我在程式中利用DirectoryListBox來開啟檔案,但是如果點選光碟機,如果
光碟機中無光碟片就會出現錯誤,我在站上尋找相關文章,
找到jest0024大大發表的文章:如下 "放置個TApplicationEvents物件攔劫例外
procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
E: Exception);
begin
if e is EInOutError then begin
if GetLastError=21 then ShowMessage('光碟機沒光碟片!!');
end;
end;" 可是我找不到TApplicationEvents這個物件,直接將這個procedure寫在程式中
也沒反應,不知道是少作哪個步驟? 大大提供的兩個方法我都試過了,都會出現錯誤
第一個出現 undeclared identiifier TApplicationEvents
第二個出現 undeclared identiifier ApplicationEvent1Exception 麻煩大大幫我解答 謝謝
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
好像 Delphi5 還是 Delphi4 以後才有 TApplicationEvent 元件
(在元件盤的 Additional 頁)
沒有這個元件可用如下的方試試:
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private // 這裡要宣告 procedure ApplicationException(Sender: TObject; E: Exception); public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} { TForm1 } procedure TForm1.ApplicationException(Sender: TObject; E: Exception); begin if E is EInOutError then begin if GetLastError=21 then ShowMessage('光碟機沒光碟片!!'); end; end; procedure TForm1.FormCreate(Sender: TObject); begin Application.OnException := ApplicationException; end; end.發表人 - hagar 於 2005/02/18 08:39:27 |
kool0318
一般會員 發表:14 回覆:17 積分:6 註冊:2005-01-11 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
小弟這邊試的結果是會觸發 EInOutError 的
但 GetLastError 的值卻不一定是 21
大部份是 87
procedure TForm1.ApplicationException(Sender: TObject; E: Exception); var iError: integer; begin if E is EInOutError then begin iError := GetLastError; if iError=21 then ShowMessage('光碟機沒光碟片!!') else ShowMessage(SysErrorMessage(iError)); end; end;發表人 - hagar 於 2005/02/18 09:20:49 |
kool0318
一般會員 發表:14 回覆:17 積分:6 註冊:2005-01-11 發送簡訊給我 |
小弟出現的錯誤訊息是這個,所以應該還是沒觸發成功,不知道原因出在哪耶
以下是我測試的程式碼 unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl, AppEvnts; type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
procedure FormCreate(Sender: TObject);
private procedure ApplicationException(Sender: TObject; E: Exception); public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
procedure TForm1.ApplicationException(Sender: TObject; E: Exception);
var
iError: integer;
begin
if E is EInOutError then
begin
iError := GetLastError; if iError=21 then
ShowMessage('光碟機沒光碟片!!')
else
ShowMessage(SysErrorMessage(iError));
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnException := ApplicationException; end; end.
|
kool0318
一般會員 發表:14 回覆:17 積分:6 註冊:2005-01-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |