全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:877
推到 Plurk!
推到 Facebook!

如何傳值給一個unit

答題得分者是:pedro
seedbcc
高階會員


發表:232
回覆:272
積分:105
註冊:2003-12-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-05 13:57:58 IP:221.169.xxx.xxx 未訂閱
Unit A(form) unit UErrorHandle;(不含form的unit) 我要如何傳值給uerrorhandle 只要下 handle:=espcerror.create(a,b,c);即可嗎? 那麼怎麼傳值了 unit a . uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls, UErrorHandle; . procedure TDbMsg.Button1Click(Sender: TObject); begin try with qry1 do begin close; sql.Clear; sql.add('select * from parts where partsi=1'); open; end; except on E: EDatabaseError do //處理資料庫引擎錯誤 begin handle:=espcerror.create(a,b,c) end; on E: EConvertError do //處理視窗類錯誤 begin end; on E: Exception do //處理所有 VCL 錯誤 begin end; end; end; unit UErrorHandle; type ESPCError = class(Exception) private a: TStringList; b: Byte; c:integer; //錯誤訊息種類 Messagekind:string; //訊息顯示種類 protected public constructor Create(Category: Byte = 1); //1 : Error , 2 : History destructor Destroy; override; procedure ErrKindCtrl; //判斷錯誤訊息種類 end; implementation constructor ESPCError.Create(Category: Byte); begin FItems := TStringList.Create; FCategory := Category; end; destructor ESPCError.Destroy; begin FItems.Free; inherited; end; procedure ESPCError.ErrKindCtrl; //**************************************************************************** procedure ShowMessages; //4 var kind:string; begin //使用application顯示訊息方塊 {with Application do begin NormalizeTopMosts; MessageBox('This should be on top.', 'Look', [smbOK]); RestoreTopMosts; end;} end; //**************************************************************************** procedure TransToLog; //5 begin {var XXX: TLogFile XXX := TLogFile.Create(1 →Error Log, 2 →History Log) XXX.Items.Add(ACode →多國語言碼) XXX.SaveToFile XXX.Free} end; //var begin (* 1.依使用傳入的第二個變數判斷是何種錯誤訊息=>>1:資料庫,2:frm,procedure,3:E.Message 2.截取電腦產生的錯誤訊息===================>>Message.Get 3.將訊息轉換「語言」=======================>>PM.GV.GetByName('') 4.顯示錯誤訊息 =======================>>Application MessageBox 5.將訊息傳給Unit(logfile)==================>>XXX := TLogFile.Create *) {判斷何種錯誤訊息} case ErrKind of //資料庫型態 1: ShowMessages; //顯示當地語言的錯誤訊息 // TransToLog; //將前述錯誤訊息,傳給ULogFile做訊息儲存 //Frm,Procedure,Sql 2: //; //E.Message // 3: //; else // Application.messagebox('請選擇正確的種類','Kind',[smbOK]); end; end; end.
pedro
尊榮會員


發表:152
回覆:1187
積分:892
註冊:2002-06-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-05 15:18:01 IP:210.61.xxx.xxx 未訂閱
seedbcc您好 unit與unit之間要傳遞變數值 只要宣告在interface和implementation之間的section 別的unit一經uses之後, 就可以用全域變數的觀念存取變數值 您要記載例外的資訊,加載Exception的行為, 可以在您的類別ESPCError的建構子,利用參數也可以達到傳遞變數值的效果
系統時間:2024-07-03 8:44:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!