回zzywuwu得关于IdSyslogServer1Syslog得问题
开始找没有找到这个类
只好去google了
找到了这个代码得原型
type
TOnSyslogEvent = procedure(Sender: TObject; ASysLogMessage: TIdSysLogMessage;
ABinding: TIdSocketHandle) of object;
TIdSyslogServer = class(TIdUDPServer)
protected
FOnSyslog: TOnSyslogEvent;
//
procedure DoSyslogEvent(AMsg: TIdSysLogMessage; ABinding: TIdSocketHandle); virtual;
procedure DoUDPRead(AData: TStream; ABinding: TIdSocketHandle); override;
public
constructor Create(AOwner: TComponent); override;
published
property DefaultPort default IdPORT_syslog;
property OnSyslog: TOnSyslogEvent read FOnSyslog write FOnSysLog;
end;
implementation
uses
SysUtils;
{ TIdSyslogServer }
procedure TIdSyslogServer.DoUDPRead(AData: TStream; ABinding: TIdSocketHandle);
var
LMsg: TIdSysLogMessage;
begin
inherited DoUDPRead(AData,ABinding);
LMsg := TIdSysLogMessage.Create(Self);
try
LMsg.ReadFromStream(AData, (AData as TMemoryStream).Size, ABinding.PeerIP);
DoSyslogEvent(LMsg, ABinding);
finally
FreeAndNil(LMsg)
end;
end;
procedure TIdSyslogServer.DoSyslogEvent(AMsg: TIdSysLogMessage; ABinding: TIdSocketHandle);
begin
if Assigned(FOnSyslog) and assigned(AMsg)then begin
FOnSyslog(Self, AMsg, ABinding);
end;
end;
end.
很明显是从TIdUDPServer继承而来得
而消息得处理是使用了FOnSyslog: TOnSyslogEvent;这个事件
我们可以跟踪代码去看看这里做了什么处理
这是http://www.koders.com/delphi/fid804A7EDA1877E3AD6C684EEC00807237B142B83F.aspx?s=TIdSysLogMessage
实现TIdSysLogMessage
好像消息是应该没有你得那一说法!
最后总结一下
如果你是在需要,可以按照她得方法,从TIdUDPServer自己继承一个
也很方便得
[解决办法]
except
// as per RFC, on invalid/missing PRI, use value 13
on e: Exception do
begin
Pri := 13;
// Reset the position to saved value
StartPos := StartPosSave;
end;
end;
这里的这个异常出现了。。直接挑掉cb的出程序的异常那里了。
有什么办法获得这个异常?