線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3333
推到 Plurk!
推到 Facebook!

如何能對 Service 進行 Debug? 如同撰寫一般的 AP 一樣

答題得分者是:James
davidsun
初階會員


發表:57
回覆:71
積分:25
註冊:2002-04-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-22 13:30:54 IP:61.66.xxx.xxx 未訂閱
Greeting , 在下想請教各位網友,關於 Service 除錯的問題,對於 Service 的撰寫我有初步的認識,網路上也有很多的範例程式可供參考,但是對於 Service 在撰寫中,要如何除錯?我就不是很清楚了,我當初以是不是像寫 DLL 一樣,在 Run | Parameters | 指定 Host Program 就可以,但是試了很多次,始終不的其法,還望各位能指點在下,要如何能對 Service 進行 Debug ?如同撰寫一般的 AP 一樣。 謝謝您。
davidsun
初階會員


發表:57
回覆:71
積分:25
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-22 13:48:21 IP:61.66.xxx.xxx 未訂閱
大家好, 我剛剛在 Delphi Help 看到這一段關於 Service Debug 的說明: (PS : 但是不知道有沒有網友知道有更好的方法或工具呢?謝謝您) You can debug service applications by attaching to the service application process when it is already running (that is, by starting the service first, and then attaching to the debugger). To attach to the service application process, choose Run|Attach To Process, and select the service application in the resulting dialog. In some cases, this approach may fail, due to insufficient rights. If that happens, you can use the Service Control Manager to enable your service to work with the debugger: 1 First create a key called Image File Execution Options in the following registry location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion 2 Create a subkey with the same name as your service (for example, MYSERV.EXE). To this subkey, add a value of type REG_SZ, named Debugger. Use the full path to Delphi32.exe as the string value. 3 In the Services control panel applet, select your service, click Startup and check Allow Service to Interact with Desktop. On Windows NT systems, you can use another approach for debugging service applications. However, this approach can be tricky, because it requires short time intervals: 1 First, launch the application in the debugger. Wait a few seconds until it has finished loading. 2 Quickly start the service from the Control Panel or from the command line: start MyServ You must launch the service quickly (within 15-30 seconds of application startup) because the application will terminate if no service is launched.
James
高階會員


發表:10
回覆:290
積分:220
註冊:2002-07-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-22 13:55:22 IP:61.218.xxx.xxx 未訂閱
Service 的程式的確蠻難 Debug 的, 我是用個比較偷懶的方法, 你也許也 可以試試看這個工具程式 Codesite, 他主要原理是配合 DebugMessage 的 方式來做, 您可以透過以下網址找到他的網站,或者您是愛用 Open Source 的使用者的話 ,也有一套 oversea 也有想同的功能。    http://www.raize.com/DevTools/CodeSite/Default.htm
change.jian
版主


發表:29
回覆:620
積分:439
註冊:2003-06-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-22 17:33:38 IP:61.222.xxx.xxx 未訂閱
我也是用CodeSite來Debug的
davidsun
初階會員


發表:57
回覆:71
積分:25
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-12-30 09:30:18 IP:61.66.xxx.xxx 未訂閱
引言: Service 的程式的確蠻難 Debug 的, 我是用個比較偷懶的方法, 你也許也 可以試試看這個工具程式 Codesite, 他主要原理是配合 DebugMessage 的 方式來做, 您可以透過以下網址找到他的網站,或者您是愛用 Open Source 的使用者的話 ,也有一套 oversea 也有想同的功能。 http://www.raize.com/DevTools/CodeSite/Default.htm
感謝兩位的熱心指點,謝謝你們。...
Dennies
一般會員


發表:1
回覆:12
積分:2
註冊:2006-07-27

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-11-17 16:35:44 IP:60.251.xxx.xxx 訂閱
給你一個建議, 這個方式是我一直以來寫 service 的時候用的.

1. 先把寫好的 Service 註冊好. (先在 Run->Paramenter 裡面加入 "/install",
按 F9 執行一次就會把我們寫的 Service 註冊進去了)

2. 從系統的 "服務" 控制面板裡找到我們剛寫好的 Service, 讓它啟動.

3. 從 Delphi 的 Run->Attach to Process 找到已經在記憶體裡面的 Service 程式.
(其名稱會跟我們寫的專案一致).

4. Attached 之後, 就會進入 Delphi 的 IDE 裡面, 就能設定 BreakPoint 來攔截各種
我們想要中斷的條件了.

限制: Start 那部分沒辦法用這方式來除錯...... Service 裡面本來就不能出現 UI,
所以 UI 也無法透過這方式進行偵錯. 跟大家分享一下, 這方法我在 Delphi 2005
以後的各版本都試過, 目前用的 Delphi and C Builder 2009 也行的.
系統時間:2024-04-27 1:21:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!