博文

UTF8编码解码(2006-05-24 19:10:00)

摘要:{*******************************************************************************   UTF-8就是以8位为单元对UCS进行编码。从UCS-2到UTF-8的编码方式如下:   UCS-2编码(16进制) UTF-8 字节流(二进制)   0000 - 007F 0xxxxxxx  0080 - 07FF 110xxxxx 10xxxxxx  0800 - FFFF 1110xxxx 10xxxxxx 10xxxxxx   例如“汉”字的Unicode编码是6C49。6C49在0800-FFFF之间,所以肯定要用3字节模板了:1110xxxx 10xxxxxx 10xxxxxx。将6C49写成二进制是:0110 110001 001001, 用这个比特流依次代替模板中的x,得到:11100110 10110001 10001001,即E6 B1 89。 *******************************************************************************} unit uUnicodeUtils; interfaceuses SysUtils, windows; function Gb2Utf8(const GbStr:String):String;function Utf82Gb(const Utf8Str:String):String; implementation function Gb2Utf8(const GbStr:String):String;var  wideStr:array[0..2048] of WideChar;  SourceLength:integer;  DoneLength:integer;  AscNo:integer;  Byte1,Byte2,Byte3:integer;begin  Result := '';  //不做变化  //Result:=GbStr;  //exit;   SourceLength := Len......

阅读全文(4399) | 评论:0

写日志的接口(2006-05-24 18:58:00)

摘要:unit uProgLog; interface uses  Windows, SysUtils, SyncObjs; const  C_LOG_LEVEL_TRACE   = $00000001;  C_LOG_LEVEL_WARNING = $00000002;  C_LOG_LEVEL_ERROR   = $00000004;type  EnumSeverity = (TraceLevel, WarningLevel, ErrorLevel, LogLevel);   function SeverityDesc(severity: EnumSeverity): string; type  TLogFile = class  private    FLogKeepDays: Integer; //日志保存时间    FLogLevel: DWORD;      //日志级别    FLogPath: string;      //日志保存路径,以"\"结尾    FLogAppName: string;   //应用程序名(日志文件前缀)     FCsWriteLogFile: TCriticalSection;    FLogFile: TextFile;    //日志文件句柄    FLogOpened: Boolean;   //日志文件是否打开    FFileTimeStamp: TTimeStamp;  //当前日志文件创建或打开时间     function GetLogKeepDays(): Integer;    procedure Se......

阅读全文(2940) | 评论:0

读写注册表的接口程序(2006-05-24 18:56:00)

摘要:替换掉红色部分 unit uReadWriteReg; interface uses  registry, Windows; Const  SOFT_NAME = 'ScFltSearch';   function OpenRootKey(var Reg: TRegistry; canCreate: boolean): boolean;  procedure SetReg(Key: string; Value: string); overload;  procedure SetReg(Key: string; Value: integer); overload;  procedure SetReg(Key: string; Value: boolean); overload;  function GetReg(Key: string; var Value: string; default: string = ''): boolean; overload;  function GetReg(Key: string; var Value: integer; default: integer = 0): boolean; overload;  function GetReg(Key: string; var Value: boolean; default: boolean = false): boolean; overload;implementation function OpenRootKey(var Reg: TRegistry; canCreate: boolean): boolean;begin  result := true;  Reg := TRegistry.Create;  Reg.RootKey := HKey_CURRENT_USER;  if not Reg.KeyExists('SoftWare\' + SOFT_NAME) then  begin    Reg.OpenKey('SoftWare\' + SOFT_NAME, true);  &n......

阅读全文(2277) | 评论:0

预防打开多个窗口的小程序(2006-05-24 18:42:00)

摘要:以下红字部分是比一般程序多加入的部分,在编写时把相应部分加入工程文件的原代码并替换相应部分即可: program HotelSMS; uses  Windows,  Forms,  fmHotelSMS in 'fmHotelSMS.pas' {fmHotelSMSF},  dmData in 'dmData.pas' {dmDataM: TDataModule},  uReadWriteReg in 'uReadWriteReg.pas',  uProgLog in 'uProgLog.pas'; {$R *.res} const  strCaption = '酒店系统短信发送';var  MainHWnd,ChildHWnd: THandle;begin  //以查找窗口以保证只能同时启动一个实例  MainHWnd := FindWindow('TApplication', strCaption);  if IsWindow(MainHWnd) then  begin    ChildHWnd := GetLastActivePopUp(MainHWnd);    //激活已有的实例    SetForeGroundWindow(MainHWnd);    if (IsWindow(ChildHWnd)) and (ChildHWnd <> MainHWnd) and       IsWindowVisible(ChildHWnd) and IsWindowEnabled(ChildHWnd) then    begin      SetForeGroundWindow(ChildHWnd);    end;    Halt;  end;   Application.Initialize......

阅读全文(2598) | 评论:0