设为首页 加入收藏

TOP

Delphi7.0常用函数-属性-事件(五)
2017-10-10 12:03:46 】 浏览:3354
Tags:Delphi7.0 常用 函数 属性 事件
n
ShowMessage ('Hello world!');
end;

调用:Hello;

function Double (value: Integer) : Integer;
begin
Double := value * 2; //函数名做返回值
end;

function Double2 (value: Integer) : Integer;
begin
Result := value * 2; //Result作返回值
end;


引用参数
C++中的(&xx)
使用var关键字表示
procedure Produ(var value:Integer);
既做传递参数,又把值返回给调用程序。

procedure Produ(out value:Interger);
用作返回。

常量参数
使用const

开放数组参数
function Sum (const A: array of Integer): Integer;
var
I: Integer;
begin
Result := 0;
for I := Low(A) to High(A) do
Result := Result + A[I];
end;
可以传递大小不定的数组

类型变化的开放数组参数
可以接收多种类型的数组参数
function SumAll (const Args: array of const): Extended;

调用协定
fastcall 只要有可能,传递到CPU寄存器多达3个,操作更快
delphi3+ 缺省标记

win32 API是stdcall,win16 API是原始的Pascal调用和cdecl调用混合体

方法:
是一种特殊的函数或过程
他与类这一数据类型相对应,每个事件都定义一个方法,通常是过程。

forward 申明
欲声明一个过程或函数,而且只给出它的名字和参数,不列出其实现代码,需要在句尾加forward 关键字:
procedure Hello; forward;
可用来写递归调用
当你在一个单元(关于单元的更多内容见下一章)的interface 部分声明一个过程或一个函数时,它被认为是一个forward声明,即使没有forward关键字也一样。

过程类型
type
IntProc = procedure (var Num: Integer);

IP: IntProc;
begin
IP := otherProcedure;


函数重载 overload关键字
function Min (A,B: Integer): Integer; overload;
function Min (A,B: Int64): Int64; overload;
function Min (A,B: Single): Single; overload;
function Min (A,B: Double): Double; overload;
function Min (A,B: Extended): Extended; overload;

确省参数
procedure MessBox (Msg: string;
Caption: string = 'Warning';
Flags: LongInt = mb_OK or mb_IconHand);


字符串
ShortString
AnsiString
WideSting
如果只简单地用String定义字符串,那么该字符串可能是短字符串也可能是ANSI长字符串,这取决于$H 编译指令的值,$H+(确省)代表长字符串(ANSIString 类型)。长字符串是Delphi 库中控件使用的字符串。
SetLength (String1, 200);设置长度分配内存
类型转换,PChar(String)
SetWindowText (Handle, PChar (Label1.Caption));
GetWindowText (Handle, PChar (S1), Length (S1));

格式化字符串
format ('First %d, Second %d', [n1, n2]);//集合
d(decimal) 将整型值转换为十进制数字字符串
x (hexadecimal) 将整型值转换为十六进制数字字符串
p (pointer) 将指针值转换为十六进制数字字符串
s (string) 拷贝字符串、字符、或字符指针值到一个输出字符串
e (exponential) 将浮点值转换为指数表示的字符串
f (floating point) 将浮点值转换为浮点表示的字符串
g (general) 使用浮点或指数将浮点值转换为最短的十进制字符串
n (number) 将浮点值转换为带千位分隔符的浮点值
m (money) 将浮点值转换为现金数量表示的字符串,转换结果取决于地域设置,详见Delphi帮助文件的Currency and date/time formatting variables主题

内存
动态数组
Array1: array of Integer;
SetLength(Array1, 100);
下标从0开始

普通数组下标可以随便写
动态数组不行,Length,Hight,Low函数了解动态数组状况
for I := Low (Array1) to High (Array1) do
Array1 [I] := I;

windows相关
type
THandle = LongWord;

外部声明
// forward declaration
function LineTo (DC: HDC; X, Y: Integer): BOOL; stdcall;
// external declaration (instead of actual code)取代真实代码
function LineTo; external 'gdi32.dll' name 'LineTo';
这段声明表示函数LineTo 的代码同名保存在GDI32.DLL 动态链接库中(最重要的Windows 系统库之一)。实际应用时,外部声明中的函数名与DLL中的函数名可以不同。
与WindowsAPI对应的声明:
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,LPARAM lParam
);
=》
function EnumWindows (lpEnumFunc: TFNWndEnumProc,lParam: LPARAM): BOOL; stdcall;

回调函数
BOOL CALLBACK EnumWindowsProc (
HWND hwnd, // handle of parent window
LPARAM lParam // application-defined value
);
=>
type
EnumWindowsProc = function (Hwnd: THandle, Param: Pointer): Boolean; stdcall;
直接使用方法


Variant变量没有类型
运算效率低


单元Unit
unit unitName;
interface
// other units we need to refer to
uses
A, B, C;
// exported type definition
type
newType = TypeDefinition;
// exported constants
const
Zero = 0;
// global variables
var
Total: Integer;
// list of exported functions and procedures
procedure MyProc;
implementation
uses
D, E;
// hidden global variable
var
PartialTotal: Integer;
// all the exported functi

首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇延时程序 下一篇[上架] iOS 上架更新版本号建议

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目