6月 272014
 

在Delphi7中,使用TAdoQuery读取sybase中的数据,发现在读取numeric字段时,本来存储的是负数值,但tadoquery读出后为正数。

select workdays from workinfo

后来gg了一下,发现这是delphi的一个bug,用Delphi 2010写了一小工具,发现读取不会出现负数为正的情况,说明在后来的delphi版本中修正了此错误。跟踪代码时发现在adodb.pas中的GetFieldData函数中的子函数VarToBuffer中,delphi 2010和delphi 7有所区别,具体代码片断如下:

ftAutoInc, ftInteger:
Integer(Buffer^) := lVal;

将adodb.pas文件拷贝到工程目录下,并将delphi 2010中的此行代码拷贝到这个文件中,发现问题确实解决了,但是修改delphi的源文件还是容易为以后的开发带来隐患,所以还需要其他的办法来解决此问题。

既然是读取numeric字段会报错,那么我们可以想办法把这个字段动态的改变为其他的类型,在sql语句中通过一些数学运算即可改变,最简单的就是跟这个字段除以1(乘以1不会改变),所以最简单的解决办法就是如下更改sql语句:

select workdays / 1 as workdays from workinfo

这样就轻松解决了问题,如果大家遇到类似的问题也可以考虑这种办法来解决问题。

6月 092014
 

Windows服务作为Windows提供的一种特殊应用程序,拥有下面优点:

1. 随系统启动而启动,不需要用户手动执行,适合做后台检测程序等
2. 不用登录系统即可运行
3. 在后台运行,不与Windows桌面相互影响
4. 拥有System权限,在任务管理器中无法结束运行

Windows不建议在服务程序中与桌面有交互,在Windows Xp及以前的版本Windows服务和用户桌面还运行在一个session下,所以服务程序还可以比较轻松的与桌面进行交互。但是自Windows Vista及以后的系统中,服务程序是运行于session0中,而第一个启动的用户则运行于session1中,要想在服务中显示桌面或者与桌面程序交互要使用很复杂的技术,甚至用CreateProcess和ShellExecute启动的应用程序都无法在用户桌面中显示。

一、在Delphi中创建Windows服务程序

Delphi中提供了创建Windows服务的程序框架,生成Windows服务工程的具体方法如下,点击菜单File->New->Other,在里面寻找Service Application项目,点击OK按钮生成即可。这里会生成一个带界面的TService1类。选中TService1界面,下面介绍一下TService的相关属性和事件。

TService属性:

  • AllowPause: 是否允许暂停
  • AllowStop: 是否允许停止
  • Dependencies: 设置该服务与其他服务的依赖关系
  • DisplayName: 在Windows服务管理器中显示的名称(注意:不是服务名)
  • Name: 服务名称,使用/install参数安装时安装的服务名为此属性值
  • Interactive: 是否要与桌面进行交互
  • StartType: 服务的启动方式
  • ServiceStartName: 设定用于启动服务的用户名

TService事件:

1. procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
在该服务启动的时候调用OnStart事件,参数Started的默认为True,所以不用在该事件中再设置Started := True; 在此事件中如果判断某些条件不允许服务运行,则可以将Started置为False,这样服务将会不再启动。
2. procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
在该服务被停止的时候调用OnStop事件,Stopped的默认为True,在此事件中如果判断某些条件不允许服务停止则可将Stopped置为False来防止服务被停止。
3. procedure TService1.ServiceExecute(Sender: TService);
服务的主体执行部分,需要将服务的主要功能实现代码放在此事件中,此过程执行完毕后服务将会自动停止,所以一般在此事件中要写类似如下代码:

4.procedure TService1.ServicePause(Sender: TService; var Paused: Boolean);
在服务被暂停时调用的事件,Paused的含义类似ServiceStart事件中的Started.
5. procedure TService1.ServiceContinue(Sender: TService; var Continued: Boolean);
服务被暂停后重新启动继续执行时调用的事件,Continued的含义类似ServiceStart事件中的Started

经过简单的点击后,一个最基本的Windows服务程序已经编写完成了,编译工程,将会生成一个exe程序,本例中生成一个ServiceTest.exe。
打开命令行窗口,将目录定位到工程的输出目录,输入ServiceTest.exe /install并执行,刚才编写的服务就安装到系统中了。
卸载服务时使用ServiceTest.exe /unstall
可以在命令行后面加/silent参数,使其不弹出安装、卸载成功的提示框。
注意:使用/install这种方式安装时,服务的名字是服务窗口的类名,不是DisplayName,服务管理器中显示的是DisplayName
也可使用Windows自带的sc命令来创建或者删除服务,创建的示例代码如下:

二、一些很有用的管理服务的函数

调用方法:

{启动服务} StartServices(服务名);
{停止服务} StopServices(服务名);
{新建服务} CreateServices(服务名,exe文件路径);
{删除服务} DeleteServices(服务名);
{获取服务状态} string:=QueryServiceStatu(服务名);

注意这里的服务名是Service类的名称,不是DisplayName

三、Delphi中编写Windows服务的注意事项

1. 尽量避免使用ShowMessage等直接进行调试,容易造成服务无法响应等问题。
2. 停止服务时提示”Windows无法停止 xxx 服务(位于 本地计算机 上)” ,则可能是OnStop事件结束时将Stopped设置成了False或者OnExecute事件不能结束或者OnExecute与界面进行了不正确的交互。
3. Windows Vista及上版本的系统中不再支持服务中显示窗口,所以在这些版本的系统上,如果需要显示窗口,则要另外创建一个窗口程序,并与之用消息通讯以显示窗口。

四、一些有用的链接

Subverting Vista UAC in Both 32 and 64 bit Architectures
http://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-and-bit-Archite

如何在Windows Service里面运行程序
http://blog.sina.com.cn/s/blog_5f8817250100vooy.html

5月 142014
 

当我们需要响应鼠标滚轮效果的时候,我们需要在Form的FormMouseWheel、FormMouseWheelDown、FormMouseWheelUp事件中进行处理。如下面的代码:

但是在实际运行中我们发现,每次滚轮后Edit1的顶部位置往上或下移动了两次,这是因为TControl的DoMouseWheel调用了该事件,如果该事件中Handled返回值为true,则DoMouseWheel将认为该事件处理完毕,不在执行后边的代码,如果返回false则继续执行后面的代码。

所以如果要避免这几个事件执行多次,在执行完你要执行的操作后,返回Handled := True;即可。如下:

DoMouseWheel的代码如下:

 

11月 232013
 

  在Windows Vista、 Windows7以上Windows系统中可以支持大图标显示了,但是Delphi编译出来的程序却只能显示32×32的图标,这使Delphi编译的程序看起来很不专业。下面就把Delphi编译大图标程序的方法分享一下。

  要想使用大图标编译,首先要准备一个256×256的图标图片。

  使用图标编辑软件,如IconWorkshop打开你的 ico文件,新建一个256×256的真彩色图标,将你的图片文件导入到该图标中。保存图标后,将图标文件拷贝到你的工程目录下,假设为mainico.ico,然后在你的工程下面建一个mainico.rc的文件,在里面输入文本:

  MAINICON ICON mainico.ico

  打开命令行窗口,将目录切换到你的工程目录下,输入命令rc mainico.rc,按回车执行,这时在你的工程目录下会生成一个mainico.RES文件。

  在Delphi中打开你的工程,选择菜单Project->View Source,在{$R *.res}下面加上一行{$R Mainico.RES},再编译程序就可以了。

  Windows系统会对图标缓存,所以刚编译完可能看不到效果,可以将编译后的程序拷贝到其他地方,看是否变成大图标了。

  rc命令为调用的Microsoft Windows Resource Compiler

 

11月 162013
 

  有的时候我们要实现一个悬浮窗口,并使该窗口一直显示在桌面的工作区内。即整个窗口要一直显示在屏幕上,不能超出屏幕的上下左右边缘。此功能的实现也不难,我们需要自己写代码来响应窗口的WM_WINDOWPOSCHANGING消息,话不多说,详细代码如下供参考:

  新建一个工程,并把下面代码拷贝到工程中,运行……

 

11月 062013
 

  在Delphi中下拉框条目的宽度总是和下拉框的宽度一样,当里面的项目太长时就不能显示全了。其实Windows提供了一个CB_SETDROPPEDWIDTH消息可能定义下拉框窗口的宽度,不知道为什么Delphi一直没有添加这个功能。使用方法很简单,如下:

  SendMessage(cboIndustry.Handle, CB_SETDROPPEDWIDTH, 200, 0);

  • 第一个参数是下拉框组件的句柄
  • 第二个参数是要发送的消息
  • 第三个参数是要设定的宽度
  • 第四个参数未使用
11月 022013
 

  我们知道,Delphi2010建立的工程,在Windows7或者Vista下编译后,界面效果都是标准的Windows7或者Vista效果。但是当我们把一个Delphi7的程序升级到Delphi2010后,编译的程序仍旧是比较老的效果。那么我们如何才能让升级的源码也使用Windows7的界面效果呢,具体操作步骤如下:

  在Delphi2010中打开工程,打开菜单Project->Options,选择树形菜单中的Application,将复合框Enable runtime themes选中,确定并重新编译就可以了。

  注意:

  1. 如果使用了UAC.res,那么即使做了上述操作,界面还是经典的windows窗口界面
 Posted by on 2013-11-02
10月 252013
 

Delphi version: Delphi2010

1. SysUtils

//检查当前系统版本,如果当前系统版本大于等于AMajor.AMinor则返回true
function CheckWin32Version(AMajor: Integer; AMinor: Integer = 0): Boolean;
//获取文件版本
function GetFileVersion(const AFileName: string): Cardinal;
//将字符串转换为大写
function UpperCase(const S: string): string; overload;
function UpperCase(const S: string; LocaleOptions: TLocaleOptions): string; overload;
//将字符串转换为小写
function LowerCase(const S: string): string; overload;
function LowerCase(const S: string; LocaleOptions: TLocaleOptions): string; overload;
//比较两个字符串s1和s2,大小写第三,如果s1<s2返回小于0的值,如果s1=s2返回0,如果s1>s2返回大于0的值
function CompareStr(const S1, S2: string): Integer; overload;
function CompareStr(const S1, S2: string; LocaleOptions: TLocaleOptions): Integer; overload;
//判断两个字符串是否相等,大小写敏感,相等返回true,不相等返回false
function SameStr(const S1, S2: string): Boolean; overload;
function SameStr(const S1, S2: string; LocaleOptions: TLocaleOptions): Boolean; overload;
//比较p1和p2所指向的指定长度的内存,相等返回true,不相等返回false
function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler;
//比较两个字符串s1和s2,大小写不敏感,所有小写字母被转换为大写字母,如果s1<s2返回小于0的值,如果s1=s2返回0,如果s1>s2返回大于0的值
function CompareText(const S1, S2: string): Integer; overload;
function CompareText(const S1, S2: string; LocaleOptions: TLocaleOptions): Integer; overload;

//比较s1和s2是否相等,大小写不敏感,如果相等返回true,不相等返回false

function SameText(const S1, S2: string): Boolean; overload;
function SameText(const S1, S2: string; LocaleOptions: TLocaleOptions): Boolean; overload;

//

function AnsiUpperCase(const S: string): string; overload;
function AnsiLowerCase(const S: string): string; overload;
function AnsiCompareStr(const S1, S2: string): Integer; overload;
function AnsiSameStr(const S1, S2: string): Boolean; inline; overload;
function AnsiCompareText(const S1, S2: string): Integer; overload;
function AnsiSameText(const S1, S2: string): Boolean; inline; overload;
function AnsiStrComp(S1, S2: PAnsiChar): Integer; inline; overload;
function AnsiStrComp(S1, S2: PWideChar): Integer; inline; overload;
function AnsiStrIComp(S1, S2: PAnsiChar): Integer; inline; overload;
function AnsiStrIComp(S1, S2: PWideChar): Integer; inline; overload;
function AnsiStrLComp(S1, S2: PAnsiChar; MaxLen: Cardinal): Integer; overload;
function AnsiStrLComp(S1, S2: PWideChar; MaxLen: Cardinal): Integer; inline; overload;
function AnsiStrLIComp(S1, S2: PAnsiChar; MaxLen: Cardinal): Integer; overload;
function AnsiStrLIComp(S1, S2: PWideChar; MaxLen: Cardinal): Integer; inline; overload;
function AnsiStrLower(Str: PAnsiChar): PAnsiChar; overload;
function AnsiStrLower(Str: PWideChar): PWideChar; inline; overload;
function AnsiStrUpper(Str: PAnsiChar): PAnsiChar; overload;
function AnsiStrUpper(Str: PWideChar): PWideChar; inline; overload;
function AnsiLastChar(const S: AnsiString): PAnsiChar; overload;
function AnsiLastChar(const S: UnicodeString): PWideChar; overload;
function AnsiStrLastChar(P: PAnsiChar): PAnsiChar; overload;
function AnsiStrLastChar(P: PWideChar): PWideChar; overload;
function WideUpperCase(const S: WideString): WideString;
function WideLowerCase(const S: WideString): WideString;
function WideCompareStr(const S1, S2: WideString): Integer;
function WideSameStr(const S1, S2: WideString): Boolean; inline;
function WideCompareText(const S1, S2: WideString): Integer;
function WideSameText(const S1, S2: WideString): Boolean; inline;

//去掉头尾空格的函数

function Trim(const S: string): string; overload;
function TrimLeft(const S: string): string; overload;
function TrimRight(const S: string): string; overload;

//在字符串S的头和尾加上单引号

function QuotedStr(const S: string): string; overload;

//在字符串S的头和尾加上Quote,例如AnsiQuotedStr(‘b’, ‘c’)=cbc

function AnsiQuotedStr(const S: string; Quote: Char): string; overload;

//

function AnsiExtractQuotedStr(var Src: PAnsiChar; Quote: AnsiChar): AnsiString; overload;
function AnsiExtractQuotedStr(var Src: PWidechar; Quote: WideChar): UnicodeString; overload;

//如果S以AQuote开始和结尾,则去掉开始和结尾的AQuote,如果不是返回原字符串

function AnsiDequotedStr(const S: string; AQuote: Char): string; overload;

//将字符串中的换行符格式为指定的格式

function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle =
{$IFDEF LINUX} tlbsLF {$ENDIF}
{$IFDEF MACOSX} tlbsLF {$ENDIF}
{$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}): string; overload;

//

function IsValidIdent(const Ident: string; AllowDots: Boolean = False): Boolean;

//将整数型转换为字符串类型

function IntToStr(Value: Integer): string; overload;
function IntToStr(Value: Int64): string; overload;

//将无符号整数转换为字符串

function UIntToStr(Value: Cardinal): string; overload;
function UIntToStr(Value: UInt64): string; overload;

//将一个整数转换为十六进制字符串,Digits为最少显示多少位字符

function IntToHex(Value: Integer; Digits: Integer): string; overload;
function IntToHex(Value: Int64; Digits: Integer): string; overload;

//将一个字符串转换为整数,StrToIntDef中如果S为非整数格式字符串则返回Default

function StrToInt(const S: string): Integer; overload;
function StrToIntDef(const S: string; Default: Integer): Integer; overload;
function TryStrToInt(const S: string; out Value: Integer): Boolean; overload;

//将字符串转换为int64类型整数

function StrToInt64(const S: string): Int64; overload;
function StrToInt64Def(const S: string; const Default: Int64): Int64; overload;
function TryStrToInt64(const S: string; out Value: Int64): Boolean; overload;

//字符串类型转换为布尔类型

function StrToBool(const S: string): Boolean; overload;
function StrToBoolDef(const S: string; const Default: Boolean): Boolean; overload;
function TryStrToBool(const S: string; out Value: Boolean): Boolean; overload;

//从可执行程序的资源文件中根据Ident标识加载字符串

function LoadStr(Ident: Integer): string;

//从资源文件中加载字符串,并进行格式化操作

function FmtLoadStr(Ident: Integer; const Args: array of const): string;

//

function FileOpen(const FileName: string; Mode: LongWord): Integer;
function FileCreate(const FileName: string): Integer; overload; inline;
function FileCreate(const FileName: string; Rights: Integer): Integer; overload; inline;
function FileCreate(const FileName: string; Mode: LongWord; Rights: Integer): Integer; overload;
function FileRead(Handle: Integer; var Buffer; Count: LongWord): Integer;
function FileWrite(Handle: Integer; const Buffer; Count: LongWord): Integer;
function FileSeek(Handle, Offset, Origin: Integer): Integer; overload;
function FileSeek(Handle: Integer; const Offset: Int64; Origin: Integer): Int64; overload;
procedure FileClose(Handle: Integer); inline;
function FileAge(const FileName: string): Integer; overload; deprecated;
function FileExists(const FileName: string): Boolean;
function DirectoryExists(const Directory: string): Boolean;
function ForceDirectories(Dir: string): Boolean;

//
function FindFirst(const Path: string; Attr: Integer;var F: TSearchRec): Integer;
function FindNext(var F: TSearchRec): Integer;
procedure FindClose(var F: TSearchRec);
function FileGetDate(Handle: Integer): Integer;
function FileSetDate(const FileName: string; Age: Integer): Integer; overload;
function FileSetDate(Handle: Integer; Age: Integer): Integer; overload; platform;
function FileGetAttr(const FileName: string): Integer; platform;
function FileSetAttr(const FileName: string; Attr: Integer): Integer; platform; 
function FileIsReadOnly(const FileName: string): Boolean; inline;
function FileSetReadOnly(const FileName: string; ReadOnly: Boolean): Boolean;
function DeleteFile(const FileName: string): Boolean; inline;
function RenameFile(const OldName, NewName: string): Boolean; inline;
{ IsAssembly returns a boolean value that indicates whether the specified file is a .NET assembly. }
function IsAssembly(const FileName: string): Boolean;
function ChangeFileExt(const FileName, Extension: string): string; overload;
function ChangeFilePath(const FileName, Path: string): string; overload;
function ExtractFilePath(const FileName: string): string; overload;
function ExtractFileDir(const FileName: string): string; overload;
function ExtractFileDrive(const FileName: string): string; overload;
function ExtractFileName(const FileName: string): string; overload;
//获取文件的扩展名
function ExtractFileExt(const FileName: string): string; overload;
//将相对路径表示的文件名转换成绝对路径表示的文件名
function ExpandFileName(const FileName: string): string; overload;
function ExpandFileNameCase(const FileName: string; out MatchFound: TFilenameCaseMatch): string; overload;
function ExpandUNCFileName(const FileName: string): string; overload;
function ExtractRelativePath(const BaseName, DestName: string): string; overload;
function ExtractShortPathName(const FileName: string): string; overload;
function FileSearch(const Name, DirList: string): string;
function DiskFree(Drive: Byte): Int64;
function DiskSize(Drive: Byte): Int64;

//

function FileDateToDateTime(FileDate: Integer): TDateTime;
function DateTimeToFileDate(DateTime: TDateTime): Integer;
function GetCurrentDir: string;
function SetCurrentDir(const Dir: string): Boolean;
function CreateDir(const Dir: string): Boolean;
function RemoveDir(const Dir: string): Boolean;
//
function StrLen(const Str: PAnsiChar): Cardinal; overload;
function StrLen(const Str: PWideChar): Cardinal; overload;
function StrEnd(const Str: PAnsiChar): PAnsiChar; overload;
function StrEnd(const Str: PWideChar): PWideChar; overload;
function StrMove(Dest: PAnsiChar; const Source: PAnsiChar; Count: Cardinal): PAnsiChar; overload;
function StrMove(Dest: PWideChar; const Source: PWideChar; Count: Cardinal): PWideChar; overload;
function StrCopy(Dest: PAnsiChar; const Source: PAnsiChar): PAnsiChar; overload;
function StrCopy(Dest: PWideChar; const Source: PWideChar): PWideChar; overload;
function StrECopy(Dest: PAnsiChar; const Source: PAnsiChar): PAnsiChar; overload;
function StrECopy(Dest: PWideChar; const Source: PWideChar): PWideChar; overload;
function StrLCopy(Dest: PAnsiChar; const Source: PAnsiChar; MaxLen: Cardinal): PAnsiChar; overload;
function StrLCopy(Dest: PWideChar; const Source: PWideChar; MaxLen: Cardinal): PWideChar; overload;
function StrPCopy(Dest: PAnsiChar; const Source: AnsiString): PAnsiChar; overload;
function StrPCopy(Dest: PWideChar; const Source: UnicodeString): PWideChar; overload;
function StrPLCopy(Dest: PAnsiChar; const Source: AnsiString;
MaxLen: Cardinal): PAnsiChar; overload;
function StrPLCopy(Dest: PWideChar; const Source: UnicodeString;
MaxLen: Cardinal): PWideChar; overload;
function StrCat(Dest: PAnsiChar; const Source: PAnsiChar): PAnsiChar; overload;
function StrCat(Dest: PWideChar; const Source: PWideChar): PWideChar; overload;
function StrLCat(Dest: PAnsiChar; const Source: PAnsiChar; MaxLen: Cardinal): PAnsiChar; overload;
function StrLCat(Dest: PWideChar; const Source: PWideChar; MaxLen: Cardinal): PWideChar; overload;
function StrComp(const Str1, Str2: PAnsiChar): Integer; overload;
function StrComp(const Str1, Str2: PWideChar): Integer; overload;
function StrIComp(const Str1, Str2: PAnsiChar): Integer; overload;
function StrIComp(const Str1, Str2: PWideChar): Integer; overload;
function StrLComp(const Str1, Str2: PAnsiChar; MaxLen: Cardinal): Integer; overload;
function StrLComp(const Str1, Str2: PWideChar; MaxLen: Cardinal): Integer; overload;
function StrLIComp(const Str1, Str2: PAnsiChar; MaxLen: Cardinal): Integer; overload;
function StrLIComp(const Str1, Str2: PWideChar; MaxLen: Cardinal): Integer; overload;
function StrScan(const Str: PAnsiChar; Chr: AnsiChar): PAnsiChar; overload;
function StrScan(const Str: PWideChar; Chr: WideChar): PWideChar; overload;
function StrRScan(const Str: PAnsiChar; Chr: AnsiChar): PAnsiChar; overload;
function StrRScan(const Str: PWideChar; Chr: WideChar): PWideChar; overload;
function TextPos(Str, SubStr: PAnsiChar): PAnsiChar; overload;
function TextPos(Str, SubStr: PWideChar): PWideChar; overload;
function StrPos(const Str1, Str2: PAnsiChar): PAnsiChar; overload;
function StrPos(const Str1, Str2: PWideChar): PWideChar; overload;
function StrUpper(Str: PAnsiChar): PAnsiChar; overload;
function StrUpper(Str: PWideChar): PWideChar; overload;
function StrLower(Str: PAnsiChar): PAnsiChar; overload;
function StrLower(Str: PWideChar): PWideChar; overload;
function StrPas(const Str: PAnsiChar): AnsiString; overload;
function StrPas(const Str: PWideChar): UnicodeString; overload;
function AnsiStrAlloc(Size: Cardinal): PAnsiChar;
function WideStrAlloc(Size: Cardinal): PWideChar;
function StrAlloc(Size: Cardinal): PChar;
function StrBufSize(const Str: PAnsiChar): Cardinal; overload;
function StrBufSize(const Str: PWideChar): Cardinal; overload;
function StrNew(const Str: PAnsiChar): PAnsiChar; overload;
function StrNew(const Str: PWideChar): PWideChar; overload;
procedure StrDispose(Str: PAnsiChar); overload;
procedure StrDispose(Str: PWideChar); overload;
//
function Format(const Format: string;
const Args: array of const): string; overload;
function Format(const Format: string; const Args: array of const;
const FormatSettings: TFormatSettings): string; overload;
procedure FmtStr(var Result: string; const Format: string;
const Args: array of const); overload;
procedure FmtStr(var Result: string; const Format: string;
const Args: array of const; const FormatSettings: TFormatSettings); overload;
function StrFmt(Buffer, Format: PAnsiChar;
const Args: array of const): PAnsiChar; overload;
function StrFmt(Buffer, Format: PAnsiChar; const Args: array of const;
const FormatSettings: TFormatSettings): PAnsiChar; overload;
function StrFmt(Buffer, Format: PWideChar;
const Args: array of const): PWideChar; overload;
function StrFmt(Buffer, Format: PWideChar; const Args: array of const;
const FormatSettings: TFormatSettings): PWideChar; overload;
function StrLFmt(Buffer: PAnsiChar; MaxBufLen: Cardinal; Format: PAnsiChar;
const Args: array of const): PAnsiChar; overload;
function StrLFmt(Buffer: PAnsiChar; MaxBufLen: Cardinal; Format: PAnsiChar;
const Args: array of const;
const FormatSettings: TFormatSettings): PAnsiChar; overload;
function StrLFmt(Buffer: PWideChar; MaxBufLen: Cardinal; Format: PWideChar;
const Args: array of const): PWideChar; overload;
function StrLFmt(Buffer: PWideChar; MaxBufLen: Cardinal; Format: PWideChar;
const Args: array of const;
const FormatSettings: TFormatSettings): PWideChar; overload;
function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const): Cardinal; overload;
function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const;
const FormatSettings: TFormatSettings): Cardinal; overload;
function FormatBuf(Buffer: PWideChar; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const): Cardinal; overload;
function FormatBuf(var Buffer: UnicodeString; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const): Cardinal; overload;
function FormatBuf(Buffer: PWideChar; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const;
const FormatSettings: TFormatSettings): Cardinal; overload;
function FormatBuf(var Buffer: UnicodeString; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const;
const FormatSettings: TFormatSettings): Cardinal; overload;
function WideFormat(const Format: WideString;
const Args: array of const): WideString; overload;
function WideFormat(const Format: WideString;
const Args: array of const;
const FormatSettings: TFormatSettings): WideString; overload;
procedure WideFmtStr(var Result: WideString; const Format: WideString;
const Args: array of const); overload;
procedure WideFmtStr(var Result: WideString; const Format: WideString;
const Args: array of const; const FormatSettings: TFormatSettings); overload;
function WideFormatBuf(var Buffer; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const): Cardinal; overload;
function WideFormatBuf(var Buffer; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const;
const FormatSettings: TFormatSettings): Cardinal; overload;
//
function FloatToStr(Value: Extended): string; overload;
function FloatToStr(Value: Extended;
const FormatSettings: TFormatSettings): string; overload;
function CurrToStr(Value: Currency): string; overload;
function CurrToStr(Value: Currency;
const FormatSettings: TFormatSettings): string; overload;
function FloatToCurr(const Value: Extended): Currency;
function TryFloatToCurr(const Value: Extended; out AResult: Currency): Boolean;
function FloatToStrF(Value: Extended; Format: TFloatFormat;
Precision, Digits: Integer): string; overload;
function FloatToStrF(Value: Extended; Format: TFloatFormat;
Precision, Digits: Integer;
const FormatSettings: TFormatSettings): string; overload;
function CurrToStrF(Value: Currency; Format: TFloatFormat;
Digits: Integer): string; overload;
function CurrToStrF(Value: Currency; Format: TFloatFormat;
Digits: Integer; const FormatSettings: TFormatSettings): string; overload;
function FloatToText(BufferArg: PAnsiChar; const Value; ValueType: TFloatValue;
Format: TFloatFormat; Precision, Digits: Integer): Integer; overload;
function FloatToText(BufferArg: PWideChar; const Value; ValueType: TFloatValue;
Format: TFloatFormat; Precision, Digits: Integer): Integer; overload;
function FloatToText(BufferArg: PAnsiChar; const Value; ValueType: TFloatValue;
Format: TFloatFormat; Precision, Digits: Integer;
const FormatSettings: TFormatSettings): Integer; overload;
function FloatToText(BufferArg: PWideChar; const Value; ValueType: TFloatValue;
Format: TFloatFormat; Precision, Digits: Integer;
const FormatSettings: TFormatSettings): Integer; overload;
function FormatFloat(const Format: string; Value: Extended): string; overload;
function FormatFloat(const Format: string; Value: Extended;
const FormatSettings: TFormatSettings): string; overload;
function FormatCurr(const Format: string; Value: Currency): string; overload;
function FormatCurr(const Format: string; Value: Currency;
const FormatSettings: TFormatSettings): string; overload;
function FloatToTextFmt(Buf: PAnsiChar; const Value; ValueType: TFloatValue;
Format: PAnsiChar): Integer; overload;
function FloatToTextFmt(Buf: PAnsiChar; const Value; ValueType: TFloatValue;
Format: PAnsiChar; const FormatSettings: TFormatSettings): Integer; overload;
function FloatToTextFmt(Buf: PWideChar; const Value; ValueType: TFloatValue;
Format: PWideChar): Integer; overload;
function FloatToTextFmt(Buf: PWideChar; const Value; ValueType: TFloatValue;
Format: PWideChar; const FormatSettings: TFormatSettings): Integer; overload;
function StrToFloat(const S: string): Extended; overload;
function StrToFloat(const S: string;
const FormatSettings: TFormatSettings): Extended; overload;
function StrToFloatDef(const S: string;
const Default: Extended): Extended; overload;
function StrToFloatDef(const S: string; const Default: Extended;
const FormatSettings: TFormatSettings): Extended; overload;
function TryStrToFloat(const S: string; out Value: Extended): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Extended;
const FormatSettings: TFormatSettings): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Double): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Double;
const FormatSettings: TFormatSettings): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Single): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Single;
const FormatSettings: TFormatSettings): Boolean; overload;
function StrToCurr(const S: string): Currency; overload;
function StrToCurr(const S: string;
const FormatSettings: TFormatSettings): Currency; overload;
function StrToCurrDef(const S: string;
const Default: Currency): Currency; overload;
function StrToCurrDef(const S: string; const Default: Currency;
const FormatSettings: TFormatSettings): Currency; overload;
function TryStrToCurr(const S: string; out Value: Currency): Boolean; overload;
function TryStrToCurr(const S: string; out Value: Currency;
const FormatSettings: TFormatSettings): Boolean; overload;
function TextToFloat(Buffer: PAnsiChar; var Value;
ValueType: TFloatValue): Boolean; overload;
function TextToFloat(Buffer: PAnsiChar; var Value; ValueType: TFloatValue;
const FormatSettings: TFormatSettings): Boolean; overload;
function TextToFloat(Buffer: PWideChar; var Value;
ValueType: TFloatValue): Boolean; overload;
function TextToFloat(Buffer: PWideChar; var Value; ValueType: TFloatValue;
const FormatSettings: TFormatSettings): Boolean; overload;
function HashName(Name: PAnsiChar): Cardinal;
procedure FloatToDecimal(var Result: TFloatRec; const Value;
ValueType: TFloatValue; Precision, Decimals: Integer);
//
function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
function TimeStampToMSecs(const TimeStamp: TTimeStamp): Comp;
function EncodeDate(Year, Month, Day: Word): TDateTime;
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
function TryEncodeDate(Year, Month, Day: Word; out Date: TDateTime): Boolean;
function TryEncodeTime(Hour, Min, Sec, MSec: Word; out Time: TDateTime): Boolean;
procedure DecodeDate(const DateTime: TDateTime; var Year, Month, Day: Word);
function DecodeDateFully(const DateTime: TDateTime; var Year, Month, Day,
DOW: Word): Boolean;
procedure DecodeTime(const DateTime: TDateTime; var Hour, Min, Sec, MSec: Word);
procedure DateTimeToSystemTime(const DateTime: TDateTime; var SystemTime: TSystemTime);
function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
function DayOfWeek(const DateTime: TDateTime): Word;
function Date: TDateTime;
function Time: TDateTime;
function GetTime: TDateTime;
function Now: TDateTime;
function CurrentYear: Word;
function IncMonth(const DateTime: TDateTime; NumberOfMonths: Integer = 1): TDateTime;
procedure IncAMonth(var Year, Month, Day: Word; NumberOfMonths: Integer = 1);
procedure ReplaceTime(var DateTime: TDateTime; const NewTime: TDateTime);
procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime);
function IsLeapYear(Year: Word): Boolean;
function DateToStr(const DateTime: TDateTime): string; overload; inline;
function DateToStr(const DateTime: TDateTime;
const FormatSettings: TFormatSettings): string; overload; inline;
function TimeToStr(const DateTime: TDateTime): string; overload; inline;
function TimeToStr(const DateTime: TDateTime;
const FormatSettings: TFormatSettings): string; overload; inline;
function DateTimeToStr(const DateTime: TDateTime): string; overload; inline;
function DateTimeToStr(const DateTime: TDateTime;
const FormatSettings: TFormatSettings): string; overload; inline;
function StrToDate(const S: string): TDateTime; overload;
function StrToDate(const S: string;
const FormatSettings: TFormatSettings): TDateTime; overload;
function StrToDateDef(const S: string;
const Default: TDateTime): TDateTime; overload;
function StrToDateDef(const S: string; const Default: TDateTime;
const FormatSettings: TFormatSettings): TDateTime; overload;
function TryStrToDate(const S: string; out Value: TDateTime): Boolean; overload;
function TryStrToDate(const S: string; out Value: TDateTime;
const FormatSettings: TFormatSettings): Boolean; overload;
function StrToTime(const S: string): TDateTime; overload;
function StrToTime(const S: string;
const FormatSettings: TFormatSettings): TDateTime; overload;
function StrToTimeDef(const S: string;
const Default: TDateTime): TDateTime; overload;
function StrToTimeDef(const S: string; const Default: TDateTime;
const FormatSettings: TFormatSettings): TDateTime; overload;
function TryStrToTime(const S: string; out Value: TDateTime): Boolean; overload;
function TryStrToTime(const S: string; out Value: TDateTime;
const FormatSettings: TFormatSettings): Boolean; overload;
function StrToDateTime(const S: string): TDateTime; overload;
function StrToDateTime(const S: string;
const FormatSettings: TFormatSettings): TDateTime; overload;
function StrToDateTimeDef(const S: string;
const Default: TDateTime): TDateTime; overload;
function StrToDateTimeDef(const S: string; const Default: TDateTime;
const FormatSettings: TFormatSettings): TDateTime; overload;
function TryStrToDateTime(const S: string;
out Value: TDateTime): Boolean; overload;
function TryStrToDateTime(const S: string; out Value: TDateTime;
const FormatSettings: TFormatSettings): Boolean; overload;
function FormatDateTime(const Format: string;
DateTime: TDateTime): string; overload; inline;
function FormatDateTime(const Format: string; DateTime: TDateTime;
const FormatSettings: TFormatSettings): string; overload;
procedure DateTimeToString(var Result: string; const Format: string;
DateTime: TDateTime); overload;
procedure DateTimeToString(var Result: string; const Format: string;
DateTime: TDateTime; const FormatSettings: TFormatSettings); overload;
function FloatToDateTime(const Value: Extended): TDateTime;
function TryFloatToDateTime(const Value: Extended; out AResult: TDateTime): Boolean;
//
function SysErrorMessage(ErrorCode: Cardinal): string;
function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string; platform;
function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char; platform;
procedure GetFormatSettings;
procedure GetLocaleFormatSettings(LCID: Integer;
var FormatSettings: TFormatSettings);
//
function GetModuleName(Module: HMODULE): string;
function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
Buffer: PChar; Size: Integer): Integer;
procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
procedure Abort;
procedure OutOfMemoryError;
procedure Beep; inline;
// MBCS functions
function ByteType(const S: AnsiString; Index: Integer): TMbcsByteType; overload;
function ByteType(const S: UnicodeString; Index: Integer): TMbcsByteType; overload;
function StrByteType(Str: PAnsiChar; Index: Cardinal): TMbcsByteType; overload;
function StrByteType(Str: PWideChar; Index: Cardinal): TMbcsByteType; overload;
function ByteToCharLen(const S: AnsiString; MaxLen: Integer): Integer; overload; inline;
function ByteToCharLen(const S: UnicodeString; MaxLen: Integer): Integer; overload; inline; deprecated ‘Use ElementToCharLen.’;
function ElementToCharLen(const S: AnsiString; MaxLen: Integer): Integer; overload;
function ElementToCharLen(const S: UnicodeString; MaxLen: Integer): Integer; overload;
function CharToByteLen(const S: AnsiString; MaxLen: Integer): Integer; overload; inline;
function CharToByteLen(const S: UnicodeString; MaxLen: Integer): Integer; overload; inline; deprecated ‘Use CharToElementLen.’;
function CharToElementLen(const S: AnsiString; MaxLen: Integer): Integer; overload;
function CharToElementLen(const S: UnicodeString; MaxLen: Integer): Integer; overload;
function ByteToCharIndex(const S: AnsiString; Index: Integer): Integer; overload; inline;
function ByteToCharIndex(const S: UnicodeString; Index: Integer): Integer; overload; inline; deprecated ‘Use ElementToCharIndex.’;
function ElementToCharIndex(const S: AnsiString; Index: Integer): Integer; overload;
function ElementToCharIndex(const S: UnicodeString; Index: Integer): Integer; overload;
function CharToByteIndex(const S: AnsiString; Index: Integer): Integer; overload; inline;
function CharToByteIndex(const S: UnicodeString; Index: Integer): Integer; overload; inline; deprecated ‘Use CharToElementIndex.’;
function CharToElementIndex(const S: AnsiString; Index: Integer): Integer; overload;
function CharToElementIndex(const S: UnicodeString; Index: Integer): Integer; overload;
function StrCharLength(const Str: PAnsiChar): Integer; overload;
function StrCharLength(const Str: PWideChar): Integer; overload;
function StrNextChar(const Str: PAnsiChar): PAnsiChar; inline; overload;
function StrNextChar(const Str: PWideChar): PWideChar; overload;
function CharLength(const S: AnsiString; Index: Integer): Integer; overload;
function CharLength(const S: UnicodeString; Index: Integer): Integer; overload;
function NextCharIndex(const S: UnicodeString; Index: Integer): Integer; overload;
function NextCharIndex(const S: AnsiString; Index: Integer): Integer; overload;
function IsLeadChar(C: AnsiChar): Boolean; overload; inline;
function IsLeadChar(C: WideChar): Boolean; overload; inline;
function CharInSet(C: AnsiChar; const CharSet: TSysCharSet): Boolean; overload; inline;
function CharInSet(C: WideChar; const CharSet: TSysCharSet): Boolean; overload; inline;
function IsPathDelimiter(const S: string; Index: Integer): Boolean; overload;
function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean; overload;
function IncludeTrailingPathDelimiter(const S: string): string; overload;
function IncludeTrailingBackslash(const S: string): string; platform; overload; inline;
function ExcludeTrailingPathDelimiter(const S: string): string; overload;
function ExcludeTrailingBackslash(const S: string): string; platform; overload; inline;
function LastDelimiter(const Delimiters, S: string): Integer; overload;
function FindDelimiter(const Delimiters, S: string; StartIdx: Integer = 1): Integer;
function AnsiCompareFileName(const S1, S2: string): Integer; inline; overload;
function SameFileName(const S1, S2: string): Boolean; inline; overload;
function AnsiLowerCaseFileName(const S: string): string; overload;
function AnsiUpperCaseFileName(const S: string): string; overload;
function AnsiPos(const Substr, S: string): Integer; overload;
function AnsiStrPos(Str, SubStr: PAnsiChar): PAnsiChar; overload;
function AnsiStrPos(Str, SubStr: PWideChar): PWideChar; overload;
function AnsiStrRScan(Str: PAnsiChar; Chr: AnsiChar): PAnsiChar; overload;
function AnsiStrRScan(Str: PWideChar; Chr: WideChar): PWideChar; inline; overload;
function AnsiStrScan(Str: PAnsiChar; Chr: AnsiChar): PAnsiChar; overload;
function AnsiStrScan(Str: PWideChar; Chr: WideChar): PWideChar; overload; inline;
function StringReplace(const S, OldPattern, NewPattern: string;
Flags: TReplaceFlags): string; overload;
function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet;
MaxCol: Integer): string; overload;
function WrapText(const Line: string; MaxCol: Integer = 45): string; overload;
function FindCmdLineSwitch(const Switch: string; const Chars: TSysCharSet;
IgnoreCase: Boolean): Boolean; overload;
function FindCmdLineSwitch(const Switch: string): Boolean; overload;
function FindCmdLineSwitch(const Switch: string; IgnoreCase: Boolean): Boolean; overload;
procedure FreeAndNil(var Obj); inline;
// Interface support routines
function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean; overload;
function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload;
function Supports(const Instance: IInterface; const IID: TGUID): Boolean; overload;
function Supports(const Instance: TObject; const IID: TGUID): Boolean; overload;
function Supports(const AClass: TClass; const IID: TGUID): Boolean; overload;
function CreateGUID(out Guid: TGUID): HResult; stdcall;
function StringToGUID(const S: string): TGUID;
function GUIDToString(const GUID: TGUID): string;
function IsEqualGUID(const guid1, guid2: TGUID): Boolean; stdcall;
// Package support routines
function LoadPackage(const Name: string): HMODULE; overload;
function LoadPackage(const Name: string; AValidatePackage: TValidatePackageProc): HMODULE; overload;
procedure UnloadPackage(Module: HMODULE);
procedure GetPackageInfo(Module: HMODULE; Param: Pointer; var Flags: Integer;
InfoProc: TPackageInfoProc);
function GetPackageDescription(ModuleName: PChar): string;
procedure InitializePackage(Module: HMODULE); overload;
procedure InitializePackage(Module: HMODULE; AValidatePackage: TValidatePackageProc); overload;
procedure FinalizePackage(Module: HMODULE);
procedure RaiseLastOSError; overload;
procedure RaiseLastOSError(LastError: Integer); overload;
procedure RaiseLastWin32Error; deprecated ‘Use RaiseLastOSError’;
function Win32Check(RetVal: BOOL): BOOL; platform;
//Termination procedure support
procedure AddTerminateProc(TermProc: TTerminateProc);
function CallTerminateProcs: Boolean;
function GDAL: LongWord;
procedure RCS;
procedure RPR;

 Posted by on 2013-10-25
10月 072013
 

  刚才在开发的时候,突然不能改变工程的图标和版本等信息了,把dof文件删除掉也不起作用。后来想起来,原来在前几天把工程默认的引用的资源文件的代码去掉了{$R *.res},打开Project->View Source后,将{$R *.res}加到里面就可以了。如下所示:

Delphi版本:Delphi7

 Posted by on 2013-10-07
9月 172013
 

Delphi中读取Outlook的数据,代码如下:

 Form代码:

相关链接:
 Microsoft Outlook Constants
AppointmentItem Object Members
Items Members (Outlook)
Folders Property
Attachment Object Members
Application Object Members
ContactItem Object Members