57 lines
1.4 KiB
ObjectPascal
57 lines
1.4 KiB
ObjectPascal
unit uErrorInfo;
|
|
|
|
interface
|
|
|
|
uses System.Generics.Collections;
|
|
|
|
type
|
|
TErrorInfo=class
|
|
private
|
|
ErrorDictionary:TDictionary<String,String>;//出错提示字典
|
|
public
|
|
constructor Create; virtual;
|
|
destructor Destroy; override;
|
|
function SwitchError(sError:string):string;
|
|
end;
|
|
|
|
function ChangeErrorInfo(sError:string):string;
|
|
|
|
var
|
|
FErrorInfo:TErrorInfo;
|
|
|
|
implementation
|
|
|
|
function ChangeErrorInfo(sError:string):string;
|
|
begin
|
|
if FErrorInfo=nil then
|
|
begin
|
|
FErrorInfo:=TErrorInfo.Create;
|
|
end;
|
|
Result:=FErrorInfo.SwitchError(sError);
|
|
end;
|
|
|
|
constructor TErrorInfo.Create;
|
|
begin
|
|
inherited;
|
|
ErrorDictionary := TDictionary<String, String>.Create;
|
|
ErrorDictionary.Add('Error sending data: (12007) 无法解析服务器的名称或地址','連接數據庫服務器失败');
|
|
ErrorDictionary.Add('This serial port already opened','串口已经打开');
|
|
ErrorDictionary.Add('Error opening serial port','串口打开出错');
|
|
ErrorDictionary.Add('File handle is not a comm handle','不是有效的串口句柄');
|
|
ErrorDictionary.Add('Cannot setup comm buffer','不能设置缓存');
|
|
end;
|
|
|
|
destructor TErrorInfo.Destroy;
|
|
begin
|
|
ErrorDictionary.Free;
|
|
inherited Destroy;
|
|
end;
|
|
|
|
function TErrorInfo.SwitchError(sError:string):string;
|
|
begin
|
|
if not ErrorDictionary.TryGetValue(sError,Result) then
|
|
Result:=sError;
|
|
end;
|
|
|
|
end.
|