2009/07/09

TIdSysLog Class - SendMsg篇(三)

上次我們看到SendMessage / SendLogMessage中有其它的參數,我們再來研究一下它們的內容吧!
這次我們先從TIdSyslogFacility說起吧
顧名思義,這單字就是設備。
原文是這麼解釋的:
Indicates the facility that caused the message to be generated.
送出此訊息的設備別。

在Syslog中,除了訊息以外,再來就是發送訊息的來源,方便我們使用者做後續的追蹤。

結構大致如下

TIdSyslogFacility = (
sfKernel,
sfUserLevel,
sfMailSystem,
sfSystemDaemon,
sfSecurityOne,
sfSysLogInternal,
sfLPR,
sfNNTP,
sfUUCP,
sfClockDaemonOne,
sfSecurityTwo,
sfFTPDaemon,
sfNTP,
sfLogAudit,
sfLogAlert,
sfClockDaemonTwo,
sfLocalUseZero,
sfLocalUseOne,
sfLocalUseTwo,
sfLocalUseThree,
sfLocalUseFour,
sfLocalUseFive,
sfLocalUseSix,
sfLocalUseSeven
);


上面提到的只是發送的部份,在接收的話就只會看到「01234…n」的數字。難道我們只能後續用switch的方式來轉換為文字嗎?
其實TIdSyslogFasility也提供了反向轉換的工具:
結構如下:

function FacilityToString(
AFac: TIdSyslogFacility
): string;


這樣傳送與接收就更趨完整了吧。

參考來源:TIdSyslogFacility

2009/07/08

TIdSysLog Class - SendMsg篇(二)

這次再介紹一下IdSysLog SendMessage的內容
基本上,如果捨SendMsg而就Send的話
那麼接收端就會收到單純的Message,TimeStamp就不會追加在Message前面。

而如果要用SendMessage而又不想加TimeStamp,呃…目前我還沒找到方法…如果我有找到的話再放上來吧



TIdSysLog.SendMessage
Sends a message to the loggin daemon.

procedure SendMessage(const AMsg: TIdSysLogMessage; const AAutoTimeStamp: Boolean = true); overload;
procedure SendMessage(const AMsg: String; const AFacility: TidSyslogFacility; const ASeverity: TIdSyslogSeverity); overload;
procedure SendMessage(const AProcess: String; const AText: String; const AFacility: TidSyslogFacility; const ASeverity: TIdSyslogSeverity; const AUsePID: Boolean = False; const APID: Integer = -1); overload;

Parameters

const AMsg: TIdSysLogMessage

Syslog message instance or string.
實體Syslog message 或是 某一字串


const AAutoTimeStamp: Boolean = true

Add time stamp to the message.
增加time stamp到欲輸出的訊息

const AFacility: TidSyslogFacility

The facility for the logged message.
發送訊息的場所

const ASeverity: TIdSyslogSeverity

The severity of the logged message.
發送訊息的重要性

const AProcess: String

The process name.
發送訊息的程序名

const AText: String

Descriptive text for the syslog entry.
可讓syslog發送的描述性文字

const AUsePID: Boolean = False

Use a process ID.
是否使用程序ID (Handle),預設為「否」

const APID: Integer = -1

Process ID for the syslog entry.
可讓syslog發送的程序ID

後面的說明…有點煩雜
主要是在說明SendMessage重載了TIdSyslog後做了哪些的加強及擴充,有興趣的可以再自己翻一下底下的內容。

Description
SendMessage is an overloaded procedure in TIdSysLog used to form and transmit a message destined for the logging daemon.
One variant of SendMessage sends the existing TIdSyslogMessage instance identified in AMsg to the logging daemon. AAutoTimeStamp indicates if the current date and time should be applied to the TIdSyslogMessage.Timestamp property prior to transmission. This variant calls Send using the encode value for the message.

Other variants of SendMessage construct a new TIdSyslogMessage instance and populate it's values using the arguments specified for the procedure. Each of these overloaded procedure calls the SendMessage variant that uses the existing TIdSyslogMessage instance.

阿斗仔,你不知道我們是把技術文件是當成武俠小說在看的嗎!?

在看Indy技術文件時,發現版本越是新的文件,它的內容越是空洞。
最後還只用了一句話來處理…
IdSyslog SendLogMessage為例

TIdSysLog.SendLogMessage Method (String, String, TidSyslogFacility, TIdSyslogSeverity, Boolean, Integer)

procedure SendLogMessage(
const AProcess: String;
const AText: String;
const AFacility: TidSyslogFacility;
const ASeverity: TIdSyslogSeverity;
const AUsePID: Boolean = False;
const APID: Integer = -1
); overload;


然後再看到成員表及說明…

ParametersDescription
AProcess 
AText 
AFacility 
ASeverity 
AUsePIDDefault is False.
APIDDefault is -1.


一開始看到宣告後我會不知道這預設值為false?不知道預設值為-1?還需要你在說明中再廢言一次?
其它內容一個渣也沒掉出來……

你不知道大部份的苦命工程師是把技術文件是當成武俠小說在看的嗎!

是想叫直接用Indy10的人去自宮後回去用Indy9嗎?

你好歹…好歹也要來個前情提要吧!!!

一個混到一個不行的Open Source......不誨言的是,它很好用,真的,但前提是你要會用才行!

難怪哈利波特我看不懂,因為我是從第3集才開始看的啊啊啊啊啊啊啊!

2009/07/07

最近在Blogger找語法高亮的方法

因為在Blogger上面放一些code,如果沒加上點顏色,感覺就不像是code的樣子

所以在網路上找了些可以高亮的方法。

方法一:利用Online syntax highlighting
我找到介紹很詳盡的網站:Onile Syntax Highlighting - 線上語法高亮產生器
寫得很棒,還有圖文併茂的解說唷!

方法二:利用SyntaxHighlighter來完成高亮的處理
有一個已經實作的網站了
在這邊
補充:方法二中的brush的成員放在這裡

TIdSysLog Class - SendMsg篇(一)

TIdSysLog Class
---------------------------------
TIdSyslog SendLogMessage --Indy 10.x
TIdSyslog SendMessage --Indy 9.x (實際應用是SendMsg)
---------------------------------

Exsample:
//This is C++ Code
IdSysLog1->SendMsg("Test HI!",sfUserLevel,slInformational);


Sends a message to the logging daemon. --Indy10.1.5
Sends a message to the loggin daemon --Indy9........(看出哪裡錯了嗎?)
對Syslog Server發送一個訊息。

logging daemon 原文應該是翻成 「登錄守護靈」??
但實際指的就是接收 Syslog的機器,所以等於Syslog Server也不為過吧。

可能因原Indy9.x中的TIdSyslog SendMessage會和TIdMessageClient.SendMsg重名
(對IdSyslog.SendMsg做help查詢會查到TIdMessageClient.SendMsg)
所以才會在Indy10.x中改為SendLogMessage吧? (誤)

2009/07/03

在中國 IBM 網站發看到了一篇關於DBX及DB2的連結教學

IBM在文件漢化上真的有下一番功夫,與某O及某$牌比較起來,IBM的文件漢化功夫真的有到家!
雖然我個人沒啥機會會用到DB2,但利用 dbExpress 創建可重用組件來將 Delphi 7 連接到 DB2這篇關於DBX的設計方式真的還不賴!看得我真是心癢癢的啦!

以下節錄這篇文章的精彩片段:


儘管 TSQLTable、TSQLStoredProc 和 TSQLQuery 都只有一個特定用途,但 TSQLDataSet 卻像隻變色龍。
它可以執行這三種任務,並可以在運行時切換到所希望執行的行為。
實際的行為通過兩個屬性(CommandType 和 CommandText)來定義。
可以將 CommandType 屬性設置為 ctQuery、ctStoredProc 或 ctTable,CommandText 屬性將根據您做出的選擇顯示一個 SQL 查詢構建器(SQL Query builder),它是一個表名稱的下拉列表或存儲過程名稱的下拉列表。
SQL 查詢構建器是新出現的,因為它不是 TSQLQuery 組件本身的一部分。
.....................................
因為增加了靈活性(以及添加了設計時 SQL CommandText Editor),所以我總是更喜歡使用 TSQLDataSet 組件,而從來不使用 TSQLTable、TSQLQuery 或 TSQLStoredProc 組件。





由於全部修改一直保存在內存中,直到應用這些更新為止,因此為客戶提供一個 Undo按鈕是個不錯的主意(根據我的經驗,這常常會受到好評)。TClientdataSet 使用 UndoLastChange 方法支持 Undo,該方法的唯一一個參數指定是否希望應用程序執行這一修改(例如,如果您想將游標定位在剛剛執行撤銷操作的記錄上)。

要實現此方法,請(從 Standard 選項卡)在窗體中放入一個 TButton 組件,命名為 btnUndo,將其 Caption 設置為 Undo,然後將下面的代碼添加到組件的 OnClick 事件處理程序:



procedure TForm1.btnUndoClick(Sender: TObject);
begin
ClientdataSet1.UndoLastChange(True)
end;

發生unresolved external __fastcall #$%@#^& .OBJ的可能原因

最近在編譯程式時,三不五時給我跑這個出來,一整個火大
在網路上找了一下可能的原因,可能會有…

一、專案裡的「.obj」刪掉重新編譯
二、使用「Build」不使用「Make」試試
三、把該函式所使用的「cpp/pas」加到專案中再試試

一行錯誤,多重解法…什麼鬼!