易截截图软件、单文件、免安装、纯绿色、仅160KB

《Delphi 算法与数据结构》: 关于 const

如果参数在函数中不可能修改, 一定要使用 const;
不然, 编译器就会:
假定先修改, 先要备份; 使用前后要增减引用计数; 还要套上 try finally.
指定了 const 就可以避免以上过程从而提高效率.
unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class
(TForm)
Button1: TButton;
procedure
Button1Click(Sender: TObject);
end
;
var
Form1: TForm1;
implementation
{$R *.dfm}
//判断一个字符串中数字的个数
function
GetNum1(str: string
): Integer;
var
i: Integer;
begin
Result := 0
;
for
i := 1
to
Length(str) do
if
str[i] in
['0'
..'9'
] then
Inc(Result);
end
;
//同样的函数只是给参数加上 const
function
GetNum2(const
str: string
): Integer;
var
i: Integer;
begin
Result := 0
;
for
i := 1
to
Length(str) do
if
str[i] in
['0'
..'9'
] then
Inc(Result);
end
;
{对比测试}
procedure
TForm1.Button1Click(Sender: TObject);
var
s: string
;
n: Cardinal;
i: Integer;
begin
s := 'ABC123'
;
n := GetTickCount;
for
i := 0
to
1000000
do
GetNum1(s);
n := GetTickCount - n;
Text := IntToStr(n) + ' - '
;
n := GetTickCount;
for
i := 0
to
1000000
do
GetNum2(s);
n := GetTickCount - n;
Text := Text + IntToStr(n);
end
;
end
.


相关文档:

Delphi中实现文件拷贝的三种方法

1.调用API函数
procedure CopyFile(fromFileName,ToFileName:string);
var
f1,f2:file;
Begin
AssignFile(f1,fromFileName); file://指定源文件名
AssignFile(f2,ToFileName); file://指定目标文件名
Reset(f1);
Try
Rewrite(f2);
Try
If Lzcopy(TfileRec(f1).handle,TfileRec(f2).Handle)<0
Then
Raise ......

delphi显示 jpg、png、gif 图片及 gif 动画的方法

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Bu ......

DELPHI 实现内存修改的方法


注意:本文仅供技术交流,请勿用于非法用途。
要修改指定程序的指定地址数据,我们需要用到两个api函数,分别是ReadProcessMemory和WriteProcessMemory。
下载是函数的定义:
ReadProcessMemory
Reads data from an area of memory in a specified process. The entire area to be read must be accessible or the op ......

用Delphi从内存流中判断图片格式的代码

利用内存流来判断文件的格式,其实判断文件的前几个字节就可以简单的判断这个文件是什么类型的文件。
procedure TFrm.CheckImgType(Sender: TObject);  
var   //声明变量
   MyImage:TMemoryStream;   //内存流对象
   Buffer:Word;
   i:integer;
beg ......

delphi操作excel

(一) 使用动态创建的方法
首先创建 Excel 对象,使用ComObj:
var ExcelApp: Variant;
ExcelApp := CreateOleObject( 'Excel.Application' );
1) 显示当前窗口:
ExcelApp.Visible := True;
2) 更改 Excel 标题栏:
ExcelApp.Caption := '应用程序调用 Microsoft Excel';
3) 添加新工作簿:
ExcelApp.WorkBooks.Add ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号