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

Delphi拾遗(7) 参数与返回值

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//返回值问题
function Add(x, y: Integer): Integer;
function Add_Res(x, y: Integer): Integer;
//关于函数的参数问题
//参数可以分为: 默认参数(传值)、var(传址)、out(输出)、const(常数)四类
function MyFun1(Value: Integer): Integer;
function MyFun2(var Value: Integer): Integer;
function MyFun3(out Value: Integer): Integer;
function MyFun4(const Value: Integer): Integer;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
function TForm2.Add(x, y: Integer): Integer;
begin
Add := x + y; //使用函数名作为返回存储变量 (少用)
// Add := Add + 1; // 函数名作为返回存储变量 不能进行运算操作
end;
function TForm2.Add_Res(x, y: Integer): Integer;
begin
Result := x + y;
Result := Result + 1;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Add(2, 4))); // 6
ShowMessage(IntToStr(Add_Res(2, 4))); // 7
end;
{默认参数是传值, 会被改变}
function TForm2.MyFun1(Value: Integer): Integer;
begin
Inc(Value);
Result := Value;
end;
{var参数是传址, 会被改变}
function TForm2.MyFun2(var Value: Integer): Integer;
begin
Inc(Value);
Result := Value;
end;
{out参数是为支持Com的, 和 var 的结果是一样的, 一般我们用不着它}
function TForm2.MyFun3(out Value: Integer): Integer;
begin
Inc(Value);
Result := Value;
end;
{const参数是绝对不可以赋值的, 这是被编译器优化的方式, 尽量多用}
function TForm2.MyFun4(const Value: Integer): Integer;
begin
// Inc(Value); 常量值不能被改变,强行改变会报错
Result := Value;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
a: Integer;


相关文档:

Delphi 日期函数

Day 开头的函数

Unit
DateUtils
function DateOf(const Avalue: TDateTime): TDateTime;
描述
使用 DateOf 函数用来把一个 TDateTime 类型的变量转变成一个
只带有日期的 TDateTime 类型变量。
例如:
showmessage(DateTimetostr(dateof(now())));
你得到的是 2003/03/19
而 showmessage(DateTime ......

Delphi函数简介

                  名称   类型    说明
                    --------------------------------------------------------- ......

delphi + java 的分布式应用

结合Delphi
客户端桌面开发的优势和Java的稳健强壮特性,采用Delphi
Client + Java Server的系统架构应该是很有市场的,经过一段时间的实际项目实践,实现架构是这么实现的,供讨论:
1.后台应用服务层可采用基于Spring+Hibernate的轻量级J2EE实现,并使用Apache XML-RPC
提供客户端调用接口;
2.前台采用 Delphi
......

Delphi字符串加密解密函数


Delphi字符串加密解密函数
功能:字符串加密和解密
首先定义一个常量数组
const
      XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47); //字符串加密用
在程序里加入以下两个函数,
function Enc(Str:String):String;//字符加密函數 這是用的一個&# ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号